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

Adding a route fails #631

Closed
nareshbhatia opened this issue May 5, 2016 · 9 comments · Fixed by #639
Closed

Adding a route fails #631

nareshbhatia opened this issue May 5, 2016 · 9 comments · Fixed by #639

Comments

@nareshbhatia
Copy link

Version: [email protected]

ng g route home --default

Running the app gives the following error:

The Broccoli Plugin: [BroccoliTypeScriptCompiler] failed with:
Error: Typescript found the following errors:
/Users/nbhati/projects/angular2-seed-cli/tmp/broccoli_type_script_compiler-input_base_path-jPwD2Y7Q.tmp/0/src/app/angular2-seed-cli.component.ts (13, 45): Argument of type '{ path: string; component: typeof HomeComponent; useAsDefault: boolean; }[]' is not assignable to parameter of type 'RouteMetadata[]'.
Type '{ path: string; component: typeof HomeComponent; useAsDefault: boolean; }' is not assignable to type 'RouteMetadata'.
Brocco added a commit to Brocco/angular-cli that referenced this issue May 5, 2016
Brocco added a commit to Brocco/angular-cli that referenced this issue May 5, 2016
@nareshbhatia
Copy link
Author

FYI, this is still not working for me. I am running from master and did the npm-link thingy as described in README.md, but still the same issue.

@nareshbhatia
Copy link
Author

@Brocco, as far as I can tell, the commit above does not address this issue. The rc.1 router requires routes to be like this:

@Routes([
  new Route({path: '/home', component: HomeComponent})
])

The cli is generating this:

@Routes([
  {path: '/home', component: HomeComponent, useAsDefault: true}
])

@Brocco
Copy link
Contributor

Brocco commented May 6, 2016

@nareshbhatia right now it appears that the router does not support default, so when generating routes please do not use --default

Also an issue was found about adding the route provider when the provider array already exists on the root component.

This will be tracked via #656

@nareshbhatia
Copy link
Author

Sounds good.

@nareshbhatia
Copy link
Author

It seems that the new way to specify the default path is to simply set it to '/':

@Routes([
  new Route({path: '/', component: HomeComponent})
])

So the CLI may have to translate ng g route home --default to a path of /.

@nareshbhatia
Copy link
Author

The RC 1 router documentation is starting to come in. The examples are instantiating the default route in ngOnInit(). Here's how I modified the CLI generated code to start the app with the default route:

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}),
  new Route({path: '/about', component: AboutComponent})
])
export class AngularCliDemoAppComponent implements OnInit {
  title = 'Angular CLI Demo';

  constructor(private router: Router) {}

  ngOnInit() {
    this.router.navigate(['/']);
  }
}

@scastaldi
Copy link

scastaldi commented Jun 3, 2016

after you import.. Route, Router, you don't need new Route()
also I'm not sure why is creating the routes with + (./+home, ./+about) ... I did a little reading and this means the routes are lazy loaded :)

@shangab
Copy link

shangab commented Aug 25, 2016

Ah, what?? @routes ??

What is going on, why routing is not stable. I mean, this is backbone of every web piece guys.

@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants