Anders
Anders

Reputation: 878

Redirecting to routes defined outside current scope in aurelia

I have a situation in my project where I need to build a route to a route defined outside the current scope. Let's say I have the following routing setup

/
/cars
/cars/buy
/cars/sell
/bikes
/bikes/buy
/bikes/sell

Now on my default routing I have defined that there are 3 routes /, /cars and /bikes. When /cars is activated i append the rotues /sell and /buy to the current route definintion. Now when the user is inside /cars/buy I would like to add a link like "Do you prefer to buy a bike instead?" and link to /bikes/buy.

Switching between buy/sell is done by

router.navigateToRoute('buy');

and

router.navigateToRoute('sell');

In the corresponding view-template.

So im kinda looking for something that would let me do

router.navigateToRoute('bikes);
router.navigateToRoute('buy');

In one move.

Upvotes: 2

Views: 963

Answers (1)

Charleh
Charleh

Reputation: 14012

You can navigate directly to a route path (rather than a route name) using

router.navigate('route/href');

This will work even if child routes have not yet been registered (the router is smart enough to route to the child and wait for it to configure the router further before continuing)

In your case

router.navigate('bikes/buy');

from cars/buy should work fine

Upvotes: 3

Related Questions