Route from one child router to another

Is it possible to route from one child route (route 1) to another (route 2) by route name instead of url?

  • child router-1
    • route 1
  • child router 2
    • route 2

If not, is there a helper to create an url with params? Imagine the following route:

{ route: ['my-route/sub/:param1/:param2/:param3'], name: 'my-route', moduleId: PLATFORM.moduleName('./my-component') }

I would like to do something like this:

this.router.navigate('my-route/sub', { param1: 'value-1', param2: 'value-2': param3: 'value-3' });

Check out navigateToRoute which uses the defined route name, whereas navigate is URL based.

I know about navigateToRoute / navigate, the problem is that I can’t use navigateToRoute as routing from one child router to another seems not possible by route name.

It is possible by route url, but there I have to create the url and params manually -> this.router.generate() also requires the route name and is therefore also not possible for the same reason as above.

You would have to have a reference to the child router and use navigateToRoute on that instance.

I don’t think there is any way for a router to know about any other router or child router unless it is coded up that way with the proper references.

Maybe you could use the settings object to manage the logic needed for that?

That made me think of the interceptors that you could manipulate what happens in the main router before the navigation occurs to do something like you want as well.

I have played around with this a bit in a dumber.
Played around with passing an id that can be updated through the pipeline or dynamically modifying the route settings on the parent component load. There are probably better ways to do it, for those more savvy with the router bits and I had no specific goal but to see if I could see a change on the page.

1 Like