• 3
  • 新人请关照

angular7路由报错:Cannot match any routes

先贴上代码

appModule.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { Routes, RouterModule } from '@angular/router';
import { ProfileComponent } from './profile/profile.component';
import { PasswordsettingsComponent } from './passwordsettings/passwordsettings.component';
import { LifeIsStrangeComponent } from './life-is-strange/life-is-strange.component';

export const ROUTES: Routes = [
  { path: 'profile/:username', component: ProfileComponent,outlet:'pView' }
  
];
@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    ProfileComponent,
    PasswordsettingsComponent,
    LifeIsStrangeComponent
  ],
  imports: [
    BrowserModule,
    RouterModule.forRoot(ROUTES)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts:

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'angular-route';
}

页面app.component.html:

<a routerLink="/profile/zhz">page1</a><br>
<router-outlet name='pView'></router-outlet>

点击链接后出现如下错误:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'profile/zhz'
Error: Cannot match any routes. URL Segment: 'profile/zhz'

这里有一个问题,只要我在route配置中不指定路由输出的outlet,而且页面上一个没有name属性的<route-outlet></route-outlet>却可以正常的找到并输出路由内容。我想知道哪里出了问题?

阅读 2.3k
评论
    1 个回答
      撰写回答

      登录后参与交流、获取后续更新提醒

      相似问题
      推荐文章