Angular2路由,重页,模拟导航 [英] Angular2 Routing, heavy page, simulate navigation
问题描述
我需要对路由一些帮助。大部分的它工作正常,包括前进和后退按钮浏览器,只要我不同路线之间移动。但是,我有我只想改变 /路由/内容的重量级组件(YouTube播放器)(路线):ID
,并避免重新初始化的组件。于是我使用 Location.go(:ID)
来解决了网址。
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.
但是,现在在浏览器的前进和后退按钮不能正常工作。我以为我可以使用 Location.subscribe
挂钩的浏览器事件,改变的内容或浏览,继续前进。但..后退和前进按钮的行为不。如果我回去(到 location.go()
)的网址,就没有前进。我不能回去两次。
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.
我希望有人能在这里给我的策略......我兜兜。
好像 Location.go。(:ID)
只是不采取照顾生意
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.
推荐答案
只实现的 CanReuse 与重量级组件上,并返回真正
,那么组件实例将被保留,只是重新补充,当你回路由。
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.
这篇关于Angular2路由,重页,模拟导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!