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.
Asked
Active
Viewed 2,932 times
7

Loren
- 13,903
- 8
- 48
- 79
-
Drop the / - > Router.go('foo') – Guidouil Feb 05 '15 at 07:22
-
That's not working for me either. At least not calling onBeforeAction again. – Loren Feb 05 '15 at 07:30
-
1Why are you trying to re-render the current route? – jimmiebtlr Feb 05 '15 at 08:05
-
you can try `window.location.reload()` this. – ajduke Feb 05 '15 at 08:16
-
@ajduke: I'd rather not make a new http request / reload the whole page (takes much more time). I have a global non-reactive (needs to be) login-check `onBeforeAction` that renders the login template instead of the current route's template. Once the user logs in, I want that function to rerun and load that route's template (but only when I tell it to, not reactively based on Meteor.userId()). – Loren Feb 06 '15 at 05:33
-
imho there needs to be a native solution for this - the "reload current view" scenario is one of the most basic aka "cancel" – B M Apr 05 '15 at 17:42
-
I think iron-router needs to add an option for routes to allow for the same route to re-execute. I have the same problem where we want to run the same search term again and we cannot have the page reactive because the data comes from an external source. I have to force the page change with a bogus incrementing query parameter. – Turbo Apr 20 '15 at 22:57
2 Answers
3
This adds a function Router.rerun()
that works:
login_dep = new Tracker.Dependency
Router.rerun = ->
login_dep.changed()
Router.configure
onBeforeAction: ->
login_dep.depend()
...

Loren
- 13,903
- 8
- 48
- 79
0
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.

Nick Lammertyn
- 396
- 1
- 5
-
That doesn't rerun eg the `onBeforeAction` hook. And doesn't work on layout templates. – Loren Feb 06 '15 at 05:30