javascript Angular 路由器错误-路由配置无效

ijxebb2r  于 2022-12-10  发布在  Java
关注(0)|答案(2)|浏览(141)

使用angular 4,我将空路径的路由重定向到 navbar 组件。所以我添加了pathMatch: full,并将此条目放在routes数组的顶部。
但我仍然得到以下错误:
zone.js:522未处理的承诺拒绝:

路由“”的配置无效:无法指定数组;

区域:根;
任务:承诺。然后;
值:区域感知错误{
__区域_符号__错误:错误:路由“”得配置无效:无法指定数组
[Zone.run=〉Angular ]

路由.组件.ts

import {Route} from '@angular/router';
import { AppComponent } from './app.component';
import {NavbarComponent} from './navbar/navbar.component';
import {RegistrationComponent} from './registration/registration.component';

export const appRoutes:Route =[
  {
   path: '',
   redirectTo: 'navbar',
   pathMatch: 'full'
  }, {
   path: 'home',
   component: NavbarComponent
  }, {
   path: 'navbar',
   component: NavbarComponent
  }, {
   path: 'registration',
   component: RegistrationComponent
  }
];

应用程序模块.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './app.component';
import {NavbarComponent} from './navbar/navbar.component';
import {RegistrationComponent} from './registration/registration.component';

import { appRoutes } from './app.route';

@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    RegistrationComponent

  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot([appRoutes])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
vfh0ocws

vfh0ocws1#

只是改变

寄件者

RouterModule.forRoot([appRoutes])

收件人

RouterModule.forRoot(appRoutes)
yk9xbfzb

yk9xbfzb2#

export const appRoutes: Route[] = [

代替

export const appRoutes:Route =[

相关问题