Angular 2儿童路线无法匹配

时间:2017-07-05 09:11:45

标签: javascript angular routing

我无法处理Angular 2路由来管理以下路由:

import {NgModule} from "@angular/core";
import {RouterModule, Routes} from "@angular/router";
import {MainMenuComponent} from "./main/main.component";
import {AdvancedMenuComponent} from "./advanced/advanced.component";
import {ImportMenuComponent} from "./import/import.component";
import {ImportTAComponent} from "./import/team-assignments/import-ta.component";
import {MenuComponent} from "./menu.component";

const menuRoutes:Routes = [
    {
        path: '',
        redirectTo: '/menu/main',
        pathMatch: 'full'
    },
    {
        path: 'menu',
        children: [
            {
                path: '',
                component: MenuComponent
            },
            {
                path: 'main',
                component: MainMenuComponent,
                outlet: 'content'
            },
            {
                path: 'advanced',
                component: AdvancedMenuComponent,
                outlet: 'content'
            },
            {
                path: 'import',
                component: ImportMenuComponent,
                outlet: 'content'
            },
            {
                path: 'import/ta',
                component: ImportTAComponent,
                outlet: 'content'
            }
        ]
    }
];

@NgModule({
    imports: [
        RouterModule.forChild(menuRoutes)
    ],
    exports: [
        RouterModule
    ]
})
export class MenuRoutingModule {
}

当我尝试访问/ menu / main时,我在控制台中遇到以下错误“无法匹配任何路由.URL段:'menu / main'”。有人可以帮我吗?我的路线出了什么问题?我怎样才能达到要求的行为?

在父母中我有以下html: <router-outlet name="content"></router-outlet>

顺便说一下,我的父母也作为路由器插座包含在一个全局模块中:

<router-outlet name="navbar"></router-outlet>
<router-outlet></router-outlet>

{
    path: '',
    component: NavbarComponent,
    outlet: 'navbar'
},
{
    path: '',
    loadChildren: 'app/menu/menu.module#MenuModule'
}

0 个答案:

没有答案