账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    angular7路由报错:Cannot match any routes
    35
    0

    先贴上代码

    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>却可以正常的找到并输出路由内容。我想知道哪里出了问题?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部