Skip to content

Adding a route fails #631

Closed
Closed

Description

@nareshbhatia

Version: angular-cli@0.0.39

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'.

Activity

  1. added 2 commits that reference this issue on May 5, 2016
    bd09056
    69174d5
  2. nareshbhatia commented on May 5, 2016

    @nareshbhatia
    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.

  3. nareshbhatia commented on May 6, 2016

    @nareshbhatia
    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}
    ])
    
  4. Brocco commented on May 6, 2016

    @Brocco
    Contributor

    @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

  5. nareshbhatia commented on May 6, 2016

    @nareshbhatia
    Author

    Sounds good.

  6. nareshbhatia commented on May 6, 2016

    @nareshbhatia
    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 /.

  7. nareshbhatia commented on May 6, 2016

    @nareshbhatia
    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(['/']);
      }
    }
    
  8. scastaldi commented on Jun 3, 2016

    @scastaldi

    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 :)

  9. shangab commented on Aug 25, 2016

    @shangab

    Ah, what?? @routes ??

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

  10. angular-automatic-lock-bot commented on Sep 6, 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.

  11. locked and limited conversation to collaborators on Sep 6, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions