Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect routes generated for angular 2 RC 1 #663

Closed
nareshbhatia opened this issue May 6, 2016 · 3 comments
Closed

Incorrect routes generated for angular 2 RC 1 #663

nareshbhatia opened this issue May 6, 2016 · 3 comments
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@nareshbhatia
Copy link

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.

@hansl hansl added type: chore P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels May 6, 2016
@percy1984
Copy link

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
Copy link
Author

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

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

4 participants