question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use forwardTo with parameters?

See original GitHub issue

Basically I want to automatically forward this route:

/channel/:channel_id/

to this one:

/:client_id/channel/:channel_id/

But, since the first route does not specify any client_id, I want to use a default value of “foo”.

This is what I have but obviously does not work:

const router = createRouter(
	// routes
	[
		{
			name : 'channel',
			path : '/:client_id/channel/:channel_id/'
		},
		{
			name      : 'channel_old_api',
			path      : '/channel/:channel_id/',
			forwardTo : 'channel'
		}
	],
	// options
	{
		defaultRoute  : 'channel',
		defaultParams :
		{
			client_id  : 'foo',
			channel_id : 'lalala'
		},
		trailingSlash     : true,
		strictQueryParams : false
	});

If I open the browser in https://localhost/#/channel/alpha/ it fails with:

Uncaught Error: Cannot build path: '/:client_id/meet/:channel_id/' requires missing parameters { client_id }

Is there any way to use forwardTo with extra default parameters? Something like:

{
	name          : 'channel_old_api',
	path          : '/channel/:channel_id/',
	forwardTo     : 'channel',
	forwardParams : { client_id: 'foo' }
}

Thanks a lot.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
trochcommented, Jan 24, 2018

Will do! The PR is ready: #244, will probably release tomorrow or friday

1reaction
trochcommented, Jan 25, 2018

Yeah sure, the docs will be updated before release

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with forwardTo with parameters - Vaadin
But I have a strange behaviour when using forwardTo compared to rerouteTo event.forwardTo(MainView.class); becomes http://127.0.0.1/main (parameters are ...
Read more >
missing URL parameters when using event.forwardTo("xxx")
forwardTo forwards to another view and is changing the URL. But the URL parameters are lost and not transfered. When using event.
Read more >
vaadin strip query parameters when calling forwardTo
I've tried using UI.navigateTo but that doesn't appear to work in a beforeEnter handler. So how do I remove the query parameters?
Read more >
The Complete Guide to URL parameters with React Router
In this post you'll learn how to use URL parameters with React Router. ... When's the last time you actually looked forward to...
Read more >
Forward to different URL and pass parameters - CodeRanch
I need to pass some parameters with "POST" to a different site( The requestDispatcher only takes context relative paths and the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found