Reputation: 11205
I have a situation in which the user is redirected to a template (say I ). In template I, there is a condition which would determine if we should render that template or redirect to some other place.
The way I am doing right now is to check for that condition in the Template.I.onCreated()
and if that condition is true, then putting window.location.href
to the new url.
But this is sometimes causing the template I to appear briefly on screen before redirection.
I need a way to be able to stop this from happening. I thought onCreated() fires before onRendered() so it should have prevented that. But still this does not seem to work.
Upvotes: 0
Views: 63
Reputation: 20226
The simplest way to conditionally render a template in blaze is to wrap it with an {{# if}}
:
<template name="parentTemplate">
{{#if someCondition}}
{{> childTemplate }}
{{/if}}
</template>
You can define a helper in js that returns a truthy or falsy value for someCondition
. No need to do anything in onCreated
.
Changing the url via window.location.href
is highly discouraged. This will cause the entire app to be reloaded, including all the subscriptions.
Upvotes: 3