Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 { }
like image 886
Nagaraju Tammu Avatar asked Oct 17 '22 22:10

Nagaraju Tammu


1 Answers

Just change

From

RouterModule.forRoot([appRoutes])

To

RouterModule.forRoot(appRoutes)
like image 132
Sajeetharan Avatar answered Oct 21 '22 00:10

Sajeetharan