aurelia / router

A powerful client-side router.
MIT License
121 stars 115 forks source link

Child router fallback route ignored in favour of root fallback route #529

Open thinkOfaNumber opened 6 years ago

thinkOfaNumber commented 6 years ago

I'm submitting a bug report

I'm fairly certain this is a bug. At least it's very surprising and there doesn't appear to be a way to use fallback routes in child routers.

Please tell us about your environment:

To reproduce:

  1. Configure an app with route and child route pages
  2. Configure different fallback routes for the child and root router (using config.fallbackRoute())
  3. make one of the child route pages return false from canActivate()
  4. navigate to this child route without history - e.g. first page load

see also this gist run.

Expected/desired behavior:

I would expect that the fallback route is chosen based on matching the location to the child router, and choosing it's fallback route.

Actual behavior: It seems that only the root router's fallback route is used. If the root router has no fallback route (but the child router does), I get the error: "Router navigation failed, and no previous location or fallbackRoute could be restored."

  1. this is surprising (to me at least)
  2. there seems to be no way of getting the fallback route of a child router to be used

(edit) Also, my research found some issues but I think they're not related:

I'm currently working around the issue by calling return new Redirect(this.router.generate("something")); from canActivate() instead.

sousekd commented 4 years ago

I am struggling with this issue too. The application I'm developing uses child routers heavily to support sharing and bookmarking deep links. I'd love to be able to use fallbackRoute on child routers to get users as close to what they needed as possible, even if the enitity deep down in hierarchy doesn't exist anymore. Any chance of a fix?