简体   繁体   中英

Angular router error - Invalid configuration of route

Using angular 4, I am redirecting the route with an empty path to navbar component. So I have added pathMatch: full and I placed this entry at the top in routes array.

But I still get the following error:

zone.js:522 Unhandled Promise rejection:
Invalid configuration of route '' : Array cannot be specified;
Zone: root;
Task: Promise.then;
Value: ZoneAwareError {
__zone_symbol__error: Error: Invalid configuration of route '': Array cannot be specified
at Zone.run ( http://localhost:4200/polyfills.bundle.js:6405:43 ) [ => angular]

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

Just change

From

RouterModule.forRoot([appRoutes])

To

RouterModule.forRoot(appRoutes)
export const appRoutes: Route[] = [

instead of

export const appRoutes:Route =[

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM