router icon indicating copy to clipboard operation
router copied to clipboard

Child router fallback route ignored in favour of root fallback route

Open thinkOfaNumber opened this issue 7 years ago • 1 comments

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.

  • Library Version: I'm developing with aurelia-router 1.3.0. Not sure in the gistrun version, but it uses jdanyow's template.

Please tell us about your environment:

  • Operating System: Windows 7

  • Node Version: 6.11.4 and 8.6.0

  • NPM Version: 4.4.4
  • JSPM OR Webpack AND Version webpack 2.5.0
  • Browser: Chrome 61.0.3163.100

  • Language: TypeScript 2.2 / ES6

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."

  • What is the motivation / use case for changing the behavior?
  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:

  • issue 62 - seems to be misconfiguration
  • issue 431 appears to be where fallback route functionality was added
  • issue 117 seems to be about unknown routes and redirecting

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

thinkOfaNumber avatar Oct 04 '17 01:10 thinkOfaNumber

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?

sousekd avatar Jan 31 '20 03:01 sousekd