How do I reload the current iron:router route?

淺唱寂寞╮ 提交于 2019-12-19 17:31:40

问题


If I'm currently at /foo, Router.go '/foo' does nothing. I would like /foo's action hooks and rendering to be redone. I know I could make a dependency, mention it in an action hook, and invalidate it when I need to reload, I'm just hoping there's a Router.* api I can use, because that would be cleaner.


回答1:


This adds a function Router.rerun() that works:

login_dep = new Tracker.Dependency

Router.rerun = ->
  login_dep.changed()

Router.configure
  onBeforeAction: ->
    login_dep.depend()
    ...



回答2:


There is a way with iron router:

Router.current().render(Template.yourMainTemplateName).data();

I wouldn't recommend it though. Isn't there a way to rewrite it so it doesn't need to reload?

Another solution (perhaps better, depends on the use case) would be to have an Autorun function in your main template rendered callback. If you define your dependencies with Template.getData() it should run the code inside whenever the data changes.



来源:https://stackoverflow.com/questions/28338091/how-do-i-reload-the-current-ironrouter-route

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