RedirectTo and canLoad of lifecycleHooks

RedirectTo not working with canLoad of @lifecycleHooks. If you comment canLoad function, redirectTo works. Could someone help me, please?

1 Like

@Sayan751 sorry for the tag. The problem is async canLoad, could you see this?

Hi @DanieleRosada! Can you please elaborate a little bit more, what exactly isnā€™t working? I have forked your example, and it seems to be working.

I see two behavioral patterns in ā€œasync canLoad" and "canLoadā€, a function of lifecyclehook component. In the first case, redirectTo is in the middle state and by that I need to press Dashboard link to see the child viewport. In the second case the redirecting is automatic.
I need to understand if that is the right way to use redirectTo or if it is a bug.

Sorry. I have missed the obvious point.

I have tried your example with @aurelia/router-lite: discourse 5055 - StackBlitz. It seems to be working as expected. If your routing needs are limited to configured routing or if your project is not yet coupled with the @aurelia/router, you may once give the @aurelia/router-lite a try.

As for why it is not working for @aurelia/router, I am not sure. @jwx maybe something is missed in the example?

Iā€™m back after one week of trial with @aurelia/router-lite. It works well, nice job.
Hereā€™s a list of doubts I still have:

BUGS

QUESTIONS

  • Why routes like this {path: ā€˜ā€™, redirectTo: ā€˜homeā€™} are inside @IRouteContext.navigationModel.routes?
  • Why, if I use @IRouter router.load() in the same class of routes defined, do I need to pass the current context?

Thank you for trying out router-lite!

The bug is already been fixed, and the fix is available under the devtag. If you remove your package-lock.json, save and reload (this will regenerate the lock file), you can see it to be working. Here is a working example: bug history.back() (forked) - StackBlitz.

  • field isActive in @IRouteContext isnā€™t true when I use redirectTo

Do you mean the @IRouteContext.navigationModel.routes[i].isActive? If yes, then I have probably missed something. Thank you, reporting this. I will take a look. A temporary workaround might be to use an array of paths instead of redirectTo, depending on your use-case.

  • Why routes like this {path: ā€˜ā€™, redirectTo: ā€˜homeā€™} are inside @IRouteContext.navigationModel.routes?

This is like the NavModel (available via router.navigation) in Au1 (Au1 docs). The Au2 docs explains this.

  • Why, if I use @IRouter router.load() in the same class of routes defined, do I need to pass the current context?

This is because the IRouter instance in router-lite is singleton. And when you donā€™t specify a routing context, the default is always the root context. This is documented here.

1 Like

The bug is already been fixed, and the fix is available under the devtag. If you remove your package-lock.json, save and reload (this will regenerate the lock file), you can see it to be working. Here is a working example: bug history.back() (forked) - StackBlitz.

Youā€™re right, sorry.

Do you mean the @IRouteContext.navigationModel.routes[i].isActive ? If yes, then I have probably missed something. Thank you, reporting this. I will take a look. A temporary workaround might be to use an array of paths instead of redirectTo, depending on your use-case.

Yes I mean this.

Thanks for the documentation links

1 Like

The isActive issue with the redirectTo should be fixed now. The fix is available under the dev tag. For more information, you may refer the PR.

3 Likes