vue-meteor
vue-meteor copied to clipboard
Change Vue route from Blaze
If I include a Blaze template from Vue app which uses Vue router, and that Blaze template wants to provide a link which would change the current page/route in Vue router, how can I do that?
So what is equivalent of <router-link to="/foo">Go to Foo</router-link> in Blaze?
You can resolve a path to a route with router.resolve()
Le jeu. 13 juil. 2017 11:51, Mitar [email protected] a écrit :
If I include a Blaze template from Vue app which uses Vue router, and that Blaze template wants to provide a link which would change the current page/route in Vue router, how can I do that?
So what is equivalent of
Go to Foo in Blaze?— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/meteor-vue/vue-meteor/issues/223, or mute the thread https://github.com/notifications/unsubscribe-auth/ACqyfJwam5CPm23iVUqqVa_NKU9JtVEBks5sNei6gaJpZM4OWwqv .
But that will probably make the link a non-single-page-link and will force the browser to reload the whole app? It seems one would have to do something like:
router.push(router.resolve(...))
I have no tested any of this. The tricky thing is how to get access to router instance.
Maybe a Blaze template for this links would be useful. Something like:
{{#vue-router-link to="/foo"}}Go to Foo{{/vue-router-link}}
<a href="{{location}}">{{> Template.contentBlock}}</a>
Template['vue-router-link'].helpers({
location() {
return router.resolve(this);
}
});
Template['vue-router-link'].events({
'click a'(event) {
event.preventDefault();
router.push(router.resolve(Template.currentData()));
}
});
Not sure how to get a to match only the made anchor link.
But that will probably make the link a non-single-page-link and will force the browser to reload the whole app?
I don't think so.
router.push(router.resolve(...))
If you want to use router.push(), you don't need the resolve part, just put the route object directly.
I tested it, it reloads the page. I made this app have a link from Blaze.
I will make a Blaze template to resolve this.
I have ended up remake the package for Blaze integration, where I fixed also this. See it here.