Here is my routing in a nativescript-angular project:
const routes: Routes = [
{
path: "",
redirectTo: "/tabs/default",
pathMatch: "full"
},
{
path: "tabs",
loadChildren: "~/app/modules/tabs/tabs.module#TabsModule"
},
{
path: "login",
loadChildren: "~/app/modules/login/login.module#LoginModule"
},
{
path: "register",
loadChildren: "~/app/modules/register/register.module#RegisterModule"
}
];
@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes, {
preloadingStrategy: PreloadAllModules
})],
exports: [NativeScriptRouterModule]
})
The scenario which leads to the error: First the app starts with tabs route, then I go to the login page, after that I go to register and then again I go to tabs page (and clean the history). After that if I go to login page again and get back to previous one (tabs page), the error occurs.
The error:
JS: Error: Cannot reattach ActivatedRouteSnapshot with a different number of children
JS: at setFutureSnapshotsOfActivatedRoutes (file:///data/data/org.nativescript.tns57/files/app/tns_modules/@angular/router/bundles/router.umd.js:1950:19) [angular]
JS: at setFutureSnapshotsOfActivatedRoutes (file:///data/data/org.nativescript.tns57/files/app/tns_modules/@angular/router/bundles/router.umd.js:1954:13) [angular]
JS: at createNode (file:///data/data/org.nativescript.tns57/files/app/tns_modules/@angular/router/bundles/router.umd.js:1935:17) [angular]
JS: at file:///data/data/org.nativescript.tns57/files/app/tns_modules/@angular/router/bundles/router.umd.js:1975:20 [angular]
JS: at Array.map (<anonymous>) [angular]
JS: at createOrReuseChildren (file:///data/data/org.nativescript.tns57/files/app/tns_modules/@angular/router/bundles/router.umd.js:1958:30) [angular]
JS: at createNode (file:///data/data/org...
Any idea?
clearHistory
. – SwannRouterModule.forRoot
to initialize this orthis.router.resetConfig
? can you please add the section of the module where you use this array? – SavittforRoot
to initialize. Updated the content. Please see again. Thanks. – SwannRouteReuseStrategy
at all. (just tested the one in the answer and it didn't work) – Swann