角度:未检测到子级路线

时间:2018-09-22 06:55:01

标签: angular-ui-router angular2-routing angular6 angular2-router

这是我的dashboard.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {JwtModule} from '@auth0/angular-jwt';
import {AuthService} from '../services/auth.service';

import {dashboardComponent} from './dashboard.component';
import { foodPollComponent } from '../modules/foodPoll/foodPoll.component';
import { dashboardModuleRoutingModule } from './dashboard.routing.module';

@NgModule({
imports: [
CommonModule, dashboardModuleRoutingModule
],
declarations: [
dashboardComponent,
foodPollComponent
],
providers: [JwtModule, AuthService]
})
export class dashboardModule { }

这是我的dashboard.routing.module.ts

import { NgModule }     from '@angular/core';
import { Routes,
RouterModule } from '@angular/router';

import { dashboardComponent } from './dashboard.component';
import { foodPollComponent } from '../modules/foodPoll/foodPoll.component';

const routes: Routes = [
{
    path: 'dashboard',
    component:dashboardComponent
},
{
    path: 'dashboard/:id',
    component: dashboardComponent,
    children: [
        {
            path: 'foodPoll',
            component: foodPollComponent,
            outlet: "details"
        }
    ]
}
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class dashboardModuleRoutingModule {}

这是我的dashboard.component.html

<div class="dashboard">
 <header>Random header text</header>
 <router-outlet name="details"></router-outler>
</div>

但是,当我从 localhost:4200 / dashboard 更改为 localhost:4200 / dashboard / foodPoll 时,路由器出口视图中没有任何内容。该视图仍与仪表板页面相同。

我在哪里做错了?任何帮助,将不胜感激。 谢谢

1 个答案:

答案 0 :(得分:0)

path: 'dashboard/:id',
component: dashboardComponent,
children: [
    {
        path: 'foodPoll',
        component: foodPollComponent,
        outlet: "details"
    }
]

dashboardComponent将在网址上:"dashboard/...anything.../"

foodPollComponent将在网址上:"dashboard/...anything.../foodPoll"

:id-是dashboardComponent的动态参数