Closed
Description
I have been commenting about this in #631, but that's closed so opening a new issue.
RC 1 requires routes to be defined by new'ing Route
objects instead of passing object literals (see the router documentation). The only way I was able to make the CLI generated router code to work was by modifying it as follows:
import { Component, OnInit } from '@angular/core';
import { HomeComponent } from './+home';
import { Routes, Route, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router';
import { AboutComponent } from './+about';
@Component({
moduleId: module.id,
selector: 'angular-cli-demo-app',
templateUrl: 'angular-cli-demo.component.html',
styleUrls: ['angular-cli-demo.component.css'],
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS]
})
@Routes([
new Route({path: '/', component: HomeComponent}), // <---- see new Route({...}) here
new Route({path: '/about', component: AboutComponent})
])
export class AngularCliDemoAppComponent implements OnInit {
title = 'Angular CLI Demo';
constructor(private router: Router) {}
ngOnInit() {
this.router.navigate(['/']);
}
}
Has anyone been able to make the router work with the raw CLI generated code, i.e. just an object literal?
P.S. Also note that the default route is initialized by the code in ngOnInit()
- there is no useAsDefault
attribute any more.