jeff
jeff

Reputation: 3327

Angular2 Routing, heavy page, simulate navigation

I need to be some help on routing. Most of it works fine, including back and forward buttons in browser, as long as I am moving between different routes. But I have a heavyweight component (youtube player) (route) that I want to just change the content on /route/:id and avoid re-initializing the component. So I use the Location.go(:id) to fix up the url.

But now the back and forward buttons in the browser don't work correctly. I thought I could use Location.subscribe to hook the browser event, change the content OR navigate and move on. BUT.. the back and forward buttons aren't behaving. If I go back (to the location.go()) url, there's no forward. I can't go back twice.

I hope someone can give me a strategy here... I'm going in circles. Seems like the Location.go(:id) just isn't taking care of business.

Upvotes: 1

Views: 373

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657338

Just implement CanReuse on your heavyweight component and return true, then the component instance will be kept and just re-added when you route back.

Upvotes: 1

Related Questions