Angular2 Routing, heavy page, simulate navigation

风格不统一 提交于 2019-12-14 02:39:00

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/36249207/angular2-routing-heavy-page-simulate-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!