使用angular 4,我将带有空路径的路线重定向到
导航栏
组成部分所以我添加了
pathMatch: full
我把这个条目放在routes数组的顶部。
但我仍然得到以下错误:
区js:522未经处理的承诺拒绝:
路由“”的配置无效
:无法指定数组;
分区:根;
任务:承诺。然后
值:ZoneAwareError{
__zone\u symbol\u错误:错误:路由“”的配置无效:数组
无法指定
在区域。运行(
http://localhost:4200/polyfills.bundle.js:6405:43
)[=>角度]
路线组成部分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 { }