I am facing the issue of a angular2 component "Home" loads 2 times after 
being redirected from the Login component after user authentication. Please 
find the details about the components and routing below

I have a Login component which is part of the the LOGIN_ROUTER_PROVIDERS. 
LOGIN_ROUTER_PROVIDERS consits of following routes

const loginRoutes: Routes = [
        { path: '', component: Login },
        { path: 'login', component: Login },
        { path: 'Home', component: Home, pathMatch: 'full' },
        ...HOME_ROUTER_PROVIDERS
    ];
    export const LOGIN_ROUTER_PROVIDERS: ModuleWithProviders =    
RouterModule.forRoot(loginRoutes);

My Login component consits of the following method which has the 
redirection to Home component.

export class Login {
    ...
    public Login(userId, password)
    {
        //authenticate user and on sucessful authentication redirected to Home
         this.router.navigate(['/Home']);
    }

}

After the login/authentication, the home component and some other child 
level routing components are configured in HOME_ROUTER_PROVIDERS. 
HOME_ROUTER_PROVIDERS consits of following routing config

export const HOME_ROUTER_PROVIDERS: Routes = [
    {
        path: 'Home',
        component: Home,
        children: [
            { path: 'WorkbookList/:group', component: WorkbookList },
            { path: 'Workbook/:workbookID', component: Workbook },

            //some other child level routing components route
        ]
    }
];

Home component is as below

 export class Home {
        constructor(private _SessionService: SessionService) {
            console.log("In constructor of Home - After Login route");
        }
    }

When the application is executed and on successful authentication, the home 
component is getting loaded, but on the console I can notice that the 
statement "*In constructor of Home - After Login route*" is printed 2 times.

what is the mistake I am doing here and why the home component loads 2 
times?

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to