0

Angularjs 2 routing not working, even if I manually enter url, still not workoing.

config and versions are :-

var ngVer = '@2.0.0-rc.5'; // lock in the angular package version; do not let it float to current!

var routerVer = '@3.0.0-rc.1'; // lock router version var formsVer = '@0.3.0'; // lock forms version var routerDeprecatedVer = '@2.0.0-rc.2';

OS :- Ubuntu 14, google chrome.

app.routing.ts

import { Routes, RouterModule } from '@angular/router';

    import { HeroesComponent } from './heroes.component';


    const appRoutes: Routes = [
      {
        path: 'heroes',
        component: HeroesComponent,
        pathMatch: 'full'
      }
    ];

   export const routing = RouterModule.forRoot(appRoutes);

app.component.ts

    import { Component } from '@angular/core';
    import { AppModule } from './app.module';
    import { HeroesComponent } from './heroes.component';
    import { routing }        from './app.routing';



    @Component({
        selector : "my-app",
        template : `
                      <a routerLink="/heroes1" >Heroes</a>
                      <router-outlet></router-outlet>
          `,
        directives: [HeroesComponent]
    })
    export class AppComponent  {
      title = 'Tour of Heroes';
    }

It is not initializing, enter anything in url, its will take to home page "/"

1 Answer 1

1

There is no reason to import Heroes Component if the route is handling it. So remove the import and remove the directive in your app.component. Also it is important to go back and reference the new and proper way to construct you application with rc.5 at the official Angular.io site.

I recommend you re-do the quick start,to understand the new module.ts file, and then jump straight to the routing tutorial here to fix your current issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.