abhilash reddy
abhilash reddy

Reputation: 1586

Dynamically Loading a component which has Router Setup?

I am having a login component which loads at the beginning.After user clicks on login button i am dynamically adding component which has route config and router-links...I can see my router-links but when i click on them i cant see any content in router-outlet Here is my plunker http://plnkr.co/edit/KzCNxEthu6dRiGeSGToe?p=preview

    UserLogin() {
    this.DCLloader.loadAsRoot(AppComponent, '#login', this.injector);
}

This is how i am adding the component.My question is can i add a component which has router links dynamically? If yes, why is my demo not working? How can i correct this mistake?Somebody please help me

Upvotes: 0

Views: 287

Answers (2)

Michael Desigaud
Michael Desigaud

Reputation: 2135

I don't know what you try to achieve, but if the purpose is to redirect after a successfull login, see this example:

https://github.com/RedFroggy/angular-spring-hmac/blob/angular2/src/main/webapp/app/app.component.ts

The idea is to set the login page as the default one in the @RouteConfig. When the login is successful you redirect to a given page (/user for example). Then you have to check every time a page changes that the user is still logged and redict to the login page if he's not.

Upvotes: 0

Related Questions