使用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 { }
2条答案
按热度按时间vfh0ocws1#
只是改变
寄件者
收件人
yk9xbfzb2#
代替