gmostert / ng2-breadcrumb

This is an angular 2 component that creates a breadcrumb trail. It hooks into the angular2/router, to dynamically build up the crumb trail once a component is routed to.
MIT License
102 stars 81 forks source link

Browser refresh resets breadcrumb trail #100

Open feelthesource opened 6 years ago

feelthesource commented 6 years ago

When refreshing (browser refresh - F5) a page that contains a breadcrumb trail, the trail is lost. If the breadcrumb trail includes a prefix, only the prefix is shown after the refresh.

I think this issue is caused by the breadcrumb component's ngOnInitmethod only setting up the prefix, instead of calling the generateBreadcrumbTrailmethod.

williamchristophercooley commented 6 years ago

I'm having this issue with Ng5-Breadcrumb as well. I wonder when this fix will go out? +1

YannickAWE commented 6 years ago

Same problem for me with Ng5-Breadcrumb.

CSantosM commented 6 years ago

Hello guys, I had the same issue but i have fixed. The problem was in the ngOnInit function of breadcrum.component.ts execute this.router.events. When a user refresh the page, there isn't a event, so the subcription of the router.events doesn't work and generateBreadcrumbTrail( ) isn't called. My solution is that:

if (this.router.navigated) {
   this._urls.length = 0; //Fastest way to clear out array
   this.generateBreadcrumbTrail(this.router.routerState.snapshot.url);
   this._routerSubscription = this.router.events.subscribe( ... )
}

On this way, generateBreadcrumbTrail( ) will be called when refreshing is happend.

pablochud commented 6 years ago

Still have problem with ng-5 breadcrumbs, how to resolve that. I have seen there is PR waiting. https://github.com/gmostert/ng2-breadcrumb/pull/101

Cromies commented 6 years ago

I am using ng6-breadcrumbs and am having the same problem. is there a fix??

marquesgabriel commented 5 years ago

Hello guys, I had the same issue but i have fixed. The problem was in the ngOnInit function of breadcrum.component.ts execute this.router.events. When a user refresh the page, there isn't a event, so the subcription of the router.events doesn't work and generateBreadcrumbTrail( ) isn't called. My solution is that:

if (this.router.navigated) {
   this._urls.length = 0; //Fastest way to clear out array
   this.generateBreadcrumbTrail(this.router.routerState.snapshot.url);
   this._routerSubscription = this.router.events.subscribe( ... )
}

On this way, generateBreadcrumbTrail( ) will be called when refreshing is happend.

Would this fix work for ng6-breadcrumbs too?