Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue-Router: $router.go(-1) doesn't work in Safari

I have the following setup in the App.vue:

<top-nav></top-nav>
<main>
    <router-view v-bind="{isOnline}"></router-view>
</main>

And in the top-nav's js I have the goBack method:

methods: {
    goBack() {
        this.$router.go(-1);
    },
    ...
},

This works just fine in Chrome and Internet Explorer, not Safari though. When debugging and setting a breakpoint on that .go(-1)-line it hits the breakpoint and everything looks fine (nothing undefined). The navigation call isn't done though.

This doesn't work on mobile nor desktop. I thought Safari had support for the History API?

like image 214
sandrooco Avatar asked Nov 15 '17 07:11

sandrooco


1 Answers

I found out that the icon I used for going back was wrapped in an anchor tag with a set href attribute.

<a v-if="showBackButton" href="#" @click="goBack">
    <i class="icon icon-200-chevron-left-small"></i>
    <p>back</p>
</a>

Solution:

Change the anchor tag to a span or something and of course remove the href attribute.

like image 103
sandrooco Avatar answered Oct 16 '22 09:10

sandrooco