加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:10:35 所属栏目:安全 来源:网络整理
导读: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 rout
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 {}

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 {}

当我为应用程序提供服务时.构建成功创建,但当我运行应用程序时,我收到一个错误.我还通过删除emtpy路径检查仍然会出现此错误.

main.ts:12 Error: Invalid configuration of route '': routes must have either 
a path or a matcher specified

解决方法

无论在NgModule配置中(包括RouterModule,TranslateModule等),您都只能使用导出的变量和函数(如URLMatcher的情况),但您无法使用函数来计算值.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读