Angular无法使用其他数量的子代重新附加ActivatedRouteSnapshot [英] Angular Cannot reattach ActivatedRouteSnapshot with a different number of children

查看:194
本文介绍了Angular无法使用其他数量的子代重新附加ActivatedRouteSnapshot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在一个本机脚本角度项目中的路由:

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.

错误:

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

有什么主意吗?

推荐答案

您尝试过传递relativeTo附加功能吗?奇怪的是,这对我有用,我不知道如何以及为什么.

Did you try passing the relativeTo extras? Weirdly this worked for me and I can't figure out how and why.

this.routerExtension.back({relativeTo: this.activatedRoute});

喜欢这个.

这篇关于Angular无法使用其他数量的子代重新附加ActivatedRouteSnapshot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆