【问题标题】:child routing issue in Angular 4Angular 4中的子路由问题
【发布时间】:2017-12-09 00:03:42
【问题描述】:

我实现了子路由,但它给了我错误,我什至无法打开我在代码中提到的父页面,这是我的代码,最后提到了错误

 `import {Component} from '@angular/core';

@Component({
    template:`<div style="width:350px;hight:200px;background-color:#00ff00">
                <h1>Create Places</h1>
               </div>              
                <a [routerLink]="['/placeDetail']">PlaceDetail</a>          
              <div>                
                <router-outlet></router-outlet>
              </div>
              `
})

export class PlaceComponent{}
`

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

import { DashboardComponent }   from '../app/components/dashboard.component';
import {NeighbourhoodComponent} from '../app/components/neighbourhood.component';
import {UserProfileComponent} from '../app/components/userProfile.component';
import {PlaceComponent} from '../app/components/place.component';
import {PlaceDetailComponent} from '../app/components/placeDetail.component';


const appRoutes: Routes = [
  {
    path: '',
    redirectTo: 'dashboard',
    pathMatch: 'full'
  },
  {
    path: 'dashboard',
    component: DashboardComponent
  },
  {
    path:'neighbourhood',
    component:NeighbourhoodComponent
  },
  {
    path:'userprofile',
    component:UserProfileComponent
  },
  {
    path:'place',
    component:PlaceComponent,
    children:[
        {
          path:'placeDetail',
          component:PlaceDetailComponent
        }
      ]
  }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

一旦我点击链接,它应该转到 placeDetailComponent 但它给了我错误

异常:未捕获(承诺中):错误:无法匹配任何路由。 URL 段:“地点”

【问题讨论】:

  • 以上问题有人能回答吗?

标签: angular4-router


【解决方案1】:

问题已解决,我有 Angular 2.1,刚刚更新到 5,它正在工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-08
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2016-12-19
    • 2016-06-11
    • 2018-05-26
    相关资源
    最近更新 更多