Angular 4 router is appending components on routerLink navigation instead of destroying them -


when navigating within submodule child route sibling child route, instead of router destroying previous component, appends new 1 on navigation forward , backward.

why happening?

starting in /#/subscriber/lookup, moving /#/subscriber/register route

<a [routerlink]="['../register']">subscriber register link</a> 

app.routes.ts

/**  * angular 2 decorators , services  */  import { routes } '@angular/router';  /**  * other services  */ import { routeprotection } '../services/route-protection.service'; // import { dataresolver } './app.resolver';  /**  * imported components  */ import { logincomponent } '../login/login.component'; import { notfound404component } '../404/notfound404.component';  export const routes: routes = [{    path: '',    redirectto: 'subscriber',    pathmatch: 'full', }, {    path: 'subscriber',    loadchildren: '../+subscriber/subscriber.module#subscribermodule',    // canactivate: [routeprotection] }, {    path: 'detail',    loadchildren: '../+detail/detail.module#detailmodule',    canactivate: [routeprotection] }, {    path: 'login',    component: logincomponent }, {    path: '**',    component: notfound404component }, {    path: '404',    component: notfound404component }];  // export const routing = routermodule.forroot(routes, { usehash: true}); 

subscriber.routes.ts

/**  * imported components  */ import { subscriberlookupcomponent } './lookup/subscriber-lookup.component'; import { subscriberregistercomponent } './register/subscriber-register.component';  /*  * shared utilities & other services  */ // import { routeprotection } '../services/route-protection.service'; // import { dataresolver } '../services/app.resolver';  export const subscriberroutes = [{    path: '',    children: [{       path: '',       pathmatch: 'full',       redirectto: 'lookup'    }, {       path: 'lookup',       component: subscriberlookupcomponent, //canactivate: [routeprotection],    }, {       path: 'register',       component: subscriberregistercomponent, //canactivate: [routeprotection],  // resolve: {      'databroughttocomponent': dataresolver   }    }]  },]; 

app.module.ts

/**  * `appmodule` main entry point angular2's bootstraping process  */ @ngmodule({    bootstrap: [appcomponent],    declarations: [ // declarations contains: components, directives , pipes        // components       appcomponent, logincomponent, notfound404component, // directives       navsidebarcomponent, navheadercomponent, navfootercomponent        // pipes     ],    imports: [ // import other modules       browsermodule, sharedmodule, browseranimationsmodule, routermodule.forroot(routes, {usehash: true}), ngbmodule.forroot()       /*      applicationinsightsmodule.forroot({                instrumentationkey: '116b16e7-0307-4d62-b201-db3ea88a32c7'             })*/     ],    providers: [ // expose our services , providers angular's dependency injection       env_providers, app_providers, auth_providers] }) 

subscriber.module.ts

@ngmodule({    imports: [       sharedmodule,       commonmodule,       routermodule.forchild(subscriberroutes)    ],    declarations: [ // components / directives / pipes       subscriberlookupcomponent,       subscriberregistercomponent    ],    // exports: [    //    sharedmodule,    //    subscriberlookupcomponent,    //    subscriberregistercomponent    // ] }) 

this happens on navigation:

appending routes

update: works normal , did not change anything. cannot understand happened, maybe bug angular router or webpack dev server. investigate , update if happens again, if not delete question.

i figured out reason happening me. because viewing angular app through browsersync.

for reason, browsersync's javascript messes angular's router. i'm assuming bug. when view app directly, router works expected.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -