angular - Angular2 Componenet not rendering only on refresh -
i'm trying build angular 2 admin application,after login i'm redirected dashboard (dashboardcomponenent
) rendering when refresh page. tried several methods fix problem nothing worked.
i believe problem comes app.componenet.html
<div *ngif=" title!='login' && title!='signup'&& title!='forgot'&& title!='forgotpass'" class="wrapper"> <div class="sidebar" data-background-color="white" data-active-color="danger"> <sidebar-cmp></sidebar-cmp> </div> <div class="main-panel"> <navbar-cmp></navbar-cmp> <div class="content"> <router-outlet></router-outlet> </div> <footer-cmp></footer-cmp> </div> <!-- <fixedplugin-cmp></fixedplugin-cmp> --> </div> <div *ngif="title=='login' " class="wrapper"> <router-outlet></router-outlet> </div> <div *ngif="title=='signup' " class="wrapper"> <router-outlet></router-outlet> </div> <div *ngif="title=='forgot' " class="wrapper"> <router-outlet></router-outlet> </div> <div *ngif="title=='forgotpass' " class="wrapper"> <router-outlet></router-outlet> </div>
any idea cause of problem?
you have modify app.module.ts below. >
const approutes: routes = [
{ path: 'login', component:yourlogincomponent },
{ path: 'signup', component:yoursignupcomponent }, { path: 'forgot', component:yourforgotcomponent }, { path: 'forgotpass', component:yourforgotpasscomponent }, { path: '', redirectto: '/login', // in case no path provided pathmatch: 'full' } ];
@ngmodule({ imports: [ routermodule.forroot( approutes, { enabletracing: true } // <-- debugging purposes ) // other imports here ], ... }) export class appmodule { }
and in app.component.html can have:
<nav> <a routerlink="/login">login</a> <a routerlink="/signup">sign up</a> <a routerlink="/forgot">forgot</a> <a routerlink="/forgotpass">forgot pass</a> </nav> <router-outlet></router-outlet>
so happens here nav in app.component.html acts remote control switch channels. instruction working process of remote control defined in approutes under app.module.ts. , acts television screen see selected channel. in case there no use of multiple router outlets.
for deeper understanding can go through https://angular.io/guide/router
Comments
Post a Comment