Skip to content

Incorrect routes generated for angular 2 RC 1 #663

Closed

Description

@nareshbhatia

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

  1. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on May 6, 2016
  2. percy1984 commented on May 6, 2016

    @percy1984

    I wonder if

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

    would do the trick.

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

  3. nareshbhatia commented on May 7, 2016

    @nareshbhatia
    Author

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

  4. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions