vue-meteor icon indicating copy to clipboard operation
vue-meteor copied to clipboard

Change Vue route from Blaze

Open mitar opened this issue 8 years ago • 5 comments

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?

mitar avatar Jul 13 '17 09:07 mitar

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 .

Akryum avatar Jul 13 '17 10:07 Akryum

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.

mitar avatar Jul 13 '17 10:07 mitar

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.

Akryum avatar Jul 13 '17 11:07 Akryum

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.

mitar avatar Jul 14 '17 05:07 mitar

I have ended up remake the package for Blaze integration, where I fixed also this. See it here.

mitar avatar Jul 15 '17 09:07 mitar