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.
How do I reload the current iron:router route?
Asked Answered
This adds a function Router.rerun()
that works:
login_dep = new Tracker.Dependency
Router.rerun = ->
login_dep.changed()
Router.configure
onBeforeAction: ->
login_dep.depend()
...
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.
That doesn't rerun eg the
onBeforeAction
hook. And doesn't work on layout templates. –
Coquette © 2022 - 2024 — McMap. All rights reserved.
window.location.reload()
this. – OverstretchonBeforeAction
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()). – Coquette