angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Incorrect routes generated for angular 2 RC 1

Open nareshbhatia opened this issue 10 years ago • 3 comments

I have been commenting about this in https://github.com/angular/angular-cli/issues/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.

nareshbhatia avatar May 06 '16 19:05 nareshbhatia

I wonder if

@Routes([ {path: '/', component: HomeComponent}, {path: '/about', component: AboutComponent} ])

would do the trick.

P.S. useAsDefault was on @RouteConfig, never on @Routes....

percy1984 avatar May 06 '16 22:05 percy1984

Just installed 1.0.0-beta.0 and I cannot reproduce the problem any more. Closing the issue.

nareshbhatia avatar May 07 '16 02:05 nareshbhatia

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.