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>却可以正常的找到并输出路由内容。我想知道哪里出了问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
https://angular.io/guide/rout...
导航方式改一下