Skip to content

Change Vue route from Blaze #223

Open
@mitar

Description

@mitar
Member

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?

Activity

Akryum

Akryum commented on Jul 13, 2017

@Akryum
Collaborator
mitar

mitar commented on Jul 13, 2017

@mitar
MemberAuthor

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.

Akryum

Akryum commented on Jul 13, 2017

@Akryum
Collaborator

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.

mitar

mitar commented on Jul 14, 2017

@mitar
MemberAuthor

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

mitar commented on Jul 15, 2017

@mitar
MemberAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mitar@Akryum

        Issue actions

          Change Vue route from Blaze · Issue #223 · meteor-vue/vue-meteor