Subroutes in Angular2

断了今生、忘了曾经 提交于 2019-12-24 15:52:56

问题


I have a main component with routes:

@Routes([
            {
                path     : "/auth/login",
                component: AuthComponent
            },
            {
                path     : "/",
                component: DefaultComponent
            }
        ])

DefaultComponent routes:

@Routes([
            {
                path     : "/",
                component: LevelListComponent
            },
            {
                path     : "/levels/:id/add",
                component: LevelListComponent
            },
            {
                path     : "/levels/:id/edit",
                component: LevelListComponent
            },
            {
                path     : "/scripts",
                component: ScriptListComponent
            }
        ])

When I try to navigate to /scripts I see an error:

app.js:44947 EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'undefined'. Available routes: ['/auth/login', '/']

In beta I could do:

{
   path: "/...",
   component: SomeComponent
}

But now it's not working.

And how can I do create a dynamic route in template?

<a [routerLink]="menuItem.url">

回答1:


Reorder the routes in DefaultComponent so that the more specific ones come first and the less specific ones come last (/ to be the last one). This is a know issue and will probably be fixed with the next release.



来源:https://stackoverflow.com/questions/37384475/subroutes-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!