Angular2中的子路由 [英] Subroutes in Angular2

查看:78
本文介绍了Angular2中的子路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要路线是:

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

DefaultComponent路由:

DefaultComponent routes:

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

当我尝试导航到/scripts时,我看到一个错误:

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', '/']

在Beta版中,我可以这样做:

In beta I could do:

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

但是现在不起作用.

该如何在模板中创建动态路由?

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

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

推荐答案

DefaultComponent中的路由重新排序,以使特定的路由排在最前面,而较不特定的路由排在最后(/是最后一个).这是一个已知问题,可能会在下一版本中得到解决.

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.

这篇关于Angular2中的子路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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