nativescript-angular: Lazy loaded module route redirectTo ignored or not working
I don’t know if this is an Angular or Nativescript issue but this is not working with the latest Nativescript-angular projects, when we load a lazy module and in its routes there is an empty path that redirest to another path the redirectTo option is ignored, no matter if the path is wrong there is not error log and the view is not loaded, here i have a playground for showing the issue
If you go to home-module.routing.ts file you can see the configuration.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18
Works fine on Angular 9.1.7:
So again if CoolFeatureRoutingModule goes as a last element of NgModule imports array - redirection fails without any error in console. If CoolFeatureRoutingModule goes as a first element of NgModule imports array - everything works fine.
@darkyelox I was able to resolve your case with the usage of
childrenrouting property as shown here.For your convenience, here is the modified Playground demo. The things that have changed are the lazily loaded routing table
home-routing.module.ts
I’ve also changed the
app-routing.module.tsfile (mainly for readability to avoid multiplehomepaths but also to remove the/infront of themainpath)Remember that i’m talking about lazy loaded modules and the redirect not works no matters what i do, simply is ignored:
You can test it in the playground link in my first comment, i update it with your workaround and that not work, this issue must not be closed
I was facing issues with lazy loading modules as I’ve been generating modules with VSCode and it was registering the modules and importing them in the root module. On removing the import in root module all went fine.
@darkyelox the issue is not a bug as it appears that we should use the path without a slash For example:
Confirming that using
redirectTofrom lazily loaded module does not seem to work as expected.For everyone facing a similar problem using the RoutingModule as first import in the imports of the module works as @LeonVay said, also as @NickIliev pointed we shouldn’t use “/” in redirects ( mainly not in the root app routing module for loading a lazy module )
I was having this issues and after a day wasting searching for answers I figured out that I was adding a slash
/in the app-routing file during redirection{ path: '', redirectTo: '/dashboard', pathMatch: 'full', },make sure you don’t have a/in redirectTo like{ path: '', redirectTo: 'dashboard', pathMatch: 'full', },one question
can’t you just do
?