The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Configure Your First Angular Route

Configure Your First Angular Route

3:31
Using the Angular router requires defining routes, passing them in to the `RouterModule.forRoot` and then importing the configured `RouterModule` into your main App Module.
Watch this lesson now
Avatar
egghead.io

Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and then importing the configured RouterModule into your main App Module.

Avatar
Cameron Bourgeois

Exporting RouterModule as default doesn't work with the latest Angular 2. I had to modify it as a module and do:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthComponent } from './auth/auth.component';

const routes: Routes = [
{ path: '', component: AuthComponent }
];

@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}

In reply to egghead.io
Avatar
Brendan

I downloaded the project, ran 'npm install' and got these errors:

npm WARN angular2-in-memory-web-api@0.0.21 requires a peer of @angular/core@^2.0.0 but none was installed.
npm WARN angular2-in-memory-web-api@0.0.21 requires a peer of @angular/http@^2.0.0 but none was installed.
npm WARN angular2-in-memory-web-api@0.0.21 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN angular2-in-memory-web-api@0.0.21 requires a peer of zone.js@^0.6.25 but none was installed.

The package.json file has newer versions specified. Do I need to force it to use older versions?

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?