Search code examples
angularangular2-routingangular2-router3

Angular2 RC5 router 3.0.0 - no href in <a> in component from shared library


I have problem with generated routing link in component from shared module.

Here is the plunker.

There are 3 links in navigation menu. When I click on "Information" the page shows correctly and there should be link to Health. But Angular does not parse template and <a> tag being there has no added attribute href.

The same html code

<a routerLink="/health">Health</a>

is used both in menu (where it behaves correctly) and in LandingComponent template.

What and where should I import to have both links working?


Solution

  • Your LandingComponent is a part of SharedModule. Thus you have to import RouterModule into the SharedModule to make the link work in your LandingComponent, here's a correct code for SharedModule:

    import { NgModule } from '@angular/core';
    import { RouterModule } from '@angular/router';
    
    import { LandingComponent } from './landing.component';
    
    @NgModule({
        imports: [RouterModule],
        exports: [LandingComponent],
        declarations: [LandingComponent]
    })
    export class SharedModule { }