使用角度4,我将路径重定向到 navbar 组件的空路径。所以我添加了pathMatch: full
,并将此条目放在routes数组的顶部。
但我仍然收到以下错误:
zone.js:522未处理承诺拒绝:
路线的配置无效'' :无法指定数组;
区域:根;
任务:Promise.then;
值:ZoneAwareError {
__zone_symbol__error:错误:路由'':数组的配置无效 不能指定
在Zone.run(http://localhost:4200/polyfills.bundle.js:6405:43)[=>角]
route.component.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
}
];
app.module.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 { }
答案 0 :(得分:2)
只需更改
发件人强>
RouterModule.forRoot([appRoutes])
要强>
RouterModule.forRoot(appRoutes)