You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect routes generated for angular 2 RC 1 #663
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.
Activity
percy1984 commentedon May 6, 2016
I wonder if
@routes([
{path: '/', component: HomeComponent},
{path: '/about', component: AboutComponent}
])
would do the trick.
P.S. useAsDefault was on @RouteConfig, never on @routes....
nareshbhatia commentedon May 7, 2016
Just installed 1.0.0-beta.0 and I cannot reproduce the problem any more. Closing the issue.
angular-automatic-lock-bot commentedon Sep 5, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.