路由''的配置无效:路由必须指定路径或匹配器

Har*_*ris 7 angular-routing angular-route-segment angular2-routing angular

AppRouting.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from '../buyer/home/home.component';
const routes: Routes = [
   {path: '', redirectTo:'buyer', pathMatch:"full"}
]
@NgModule({
  declarations:[],
  imports:[
    BrowserModule,
    RouterModule.forRoot(routes)
  ],
   exports:[RouterModule]
})

export class AppRoutingModule {}
Run Code Online (Sandbox Code Playgroud)

BuyerRouting.ts

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

import { WelcomeComponent } from './welcome/welcome.component';
import { HomeComponent } from './home/home.component';

@NgModule({
declarations:[],
imports:[
    CommonModule,
    RouterModule.forChild([
        { path: 'buyer', component: HomeComponent},
        { path: '', redirectTo: '/welcome', pathMatch: 'prefix'},
        { path: 'welcome', component: WelcomeComponent}
    ])
],
exports:[RouterModule]
})

export class BuyerRoutingModule {}
Run Code Online (Sandbox Code Playgroud)

当我提供应用程序时。构建已成功创建,但是当我运行应用程序时出现错误。我还通过删除空路径进行了检查,但仍然出现此错误。

main.ts:12 Error: Invalid configuration of route '': routes must have either 
a path or a matcher specified
Run Code Online (Sandbox Code Playgroud)

Sha*_*rav 3

在 NgModule 配置(包括 RouterModule、TranslateModule 等)中的任何位置,您只能使用导出的变量和函数(如 URLMatcher 的情况),但不能使用函数来计算值。

来源: https: //github.com/angular/angular/issues/18662

因此,根据上述解决方案,您可能有一些路线(包括子路线),您正在使用任何未导出的变量或函数来计算路线。查看。