Skip to content

Latest commit

History

History
53 lines (47 loc) 路 1.58 KB

refresh.md

File metadata and controls

53 lines (47 loc) 路 1.58 KB

refresh method

FlowRouter.refresh('layout', 'template');
  • layout {String} - [required] Name of the layout template
  • template {String} - [required] Name of the intermediate template, simple <template>Loading...</template> might be a good option

FlowRouter.refresh() will force all route's rules and hooks to re-run, including subscriptions, waitOn(s) and template render. Useful in cases where template logic depends from route's hooks, example:

{{#if currentUser}}
  {{> yield}}
{{else}}
  {{> loginForm}}
{{/if}}

in example above "yielded" template may loose data context after user login action, although user login will cause yield template to render - data and waitOn hooks will not fetch new data.

Login example

Meteor.loginWithPassword({
  username: '[email protected]'
}, 'password', error => {
  if (error) {
    /* show error */
  } else {
    /* If login form has its own `/login` route, redirect to root: */
    if (FlowRouter._current.route.name === 'login') {
      FlowRouter.go('/');
    } else {
      FlowRouter.refresh('_layout', '_loading');
    }
  }
});

Logout example

Meteor.logout((error) => {
  if (error) {
    console.error(error);
  } else {
    FlowRouter.refresh('_layout', '_loading');
  }
});

Further reading