Angular 路由'的配置无效';:路由必须指定路径或匹配器
认可Angular 路由'的配置无效';:路由必须指定路径或匹配器,angular,angular2-routing,angular-routing,angular-route-segment,Angular,Angular2 Routing,Angular Routing,Angular Route Segment,认可 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 = [
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 {}
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 {}
买主
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 {}
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 {}
当我为应用程序提供服务时。构建已成功创建,但在运行应用程序时出现错误。我还通过删除emtpy路径检查了此错误是否仍然存在
main.ts:12 Error: Invalid configuration of route '': routes must have either
a path or a matcher specified
在NgModule配置中的任何位置(包括RouterModule、TranslateModule和其他),您都只能使用导出的变量和函数(如URLMatcher),但不能使用函数计算值 资料来源:
因此,根据上述解决方案,您可能有一些路由(包括子路由),其中您正在使用任何未导出的变量或函数来计算路由。检查。这是一个棘手的错误。
我使用的是一个由一些函数填充的对象,AoT静态分析我的对象,它是空的,因此我必须为AoT填充并定义完整的对象,我的计划是以某种方式在单个文件上动态更新它,就像在预构建挂钩中一样。
我在祈祷艾薇不要有这样的限制 试试这个:RouterModule.forChild([{path:'',重定向到:'/welcome',pathMatch:'prefix'},{path:'buyer',component:HomeComponent},{path:'WelcomeComponent',component:WelcomeComponent}]),然后RıuterModule被导入到appModule