Giter Site home page Giter Site logo

vue-router-back-button's Issues

Differentiate between going back and navigating to a route

Hi,
there is one problem that made this plugin unusable for me.
I need to differentiate between going back using back button and navigating through pages.

Page A => Page B => Page A (now this.$routerHistory.hasForward() returns true, even when I have not used Back button)

Error when building with Uglify/webpack

Uglify fails because it hits an error:

ERROR in static/js/vendor.js from UglifyJs
Unexpected token: punc (() [./~/vue-router-back-button/dist/index.js:1,822][static/js/vendor.js:66589,891]

history.length having a maximum value of 50 causing issues

Difficult to replicate with a failing test case as it doesn't seem jest/puppetteer has this same limitation but in the latest chrome and firefox when you get to 50 routes navigated too the length of window.history.length will always be 50 from then on. This then means the push method in this library no longer pushes anything to the session storage as the check for previousBrowserHistoryLength against window.history.length will always return true

        // Check if history length has changed since last push
        // We asume the replace function was called when not
        if (this._previousBrowserHistoryLength === window.history.length) {
            return;
        }

https://www.geeksforgeeks.org/html-dom-history-length-property/#:~:text=The%20History%20length%20property%20in,can%20be%20displayed%20in%2050.

Erratic Behaviour on Nuxt 2.14.0 (Vue router 3.3.4)

Hi,
I have installed your plugin using the provided instructions.
I have the following page structure
/feed -> /teams (no Back btn added there) -> /teams/_id (A back btn added there)

Back Btn component uses provided code:

    to () {
      if (this.client || !this.$routerHistory || !this.$routerHistory.hasPrevious()) {
        return { path: '/' }
      }

      return { path: this.$routerHistory.previous().path }
    }

Once on page /teams/_id and using BackBtn, I am taken to /feed.
If I try to navigate to another team page, same results
However, if once on Teams page I refresh entirely the app, the Back Btn takes back to another Teams page I visited previously.
Doesn't make any sense... Any idea?

Issue with multiple route paths

Currently the history stores the next and previous routes so that we can call .previous() and .next() but this poses a problem when some routes may sometimes be skipped.
If we programmatically move into a route in the future, the history does not acknowledge that we skipped routes and the .previous() route will not be the one where the user was previously.

For example, let´s say we have a route structure like this:

1 --- 2
 \   /
  1.1

And a user follows these steps:

  • 1 -> 1.1 -> 2
    History: [ "/1", "/1.1", "/2" ]

  • 2 -> 1.1 -> 1 (go back)
    History: [ "/1", "/1.1", "/2" ]

  • 1 -> 2 (skipping 1.1)
    History: [ "/1", "/1.1", "/2" ]
    Go back will now take the user to /1.1 instead of /1

You can find a reproduction here

Cant use this module

I have do this npm install vue-router-back-button --save

image

But, I cant use this module...

image

What can I do?

Error: $routerHistory is not defined on the instance but referenced during render

I'm having an error while trying to upgrade to the latest version (1.2.1) with the new install mechanism:

[Vue warn]: Property or method "$routerHistory" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

Not tracking history

Hi, I installed your plugin but it's not tracking history. I did all the installation steps and nothing. I'm using vue 2.5.17 and vue-router 3.0.2. Is it possible I forgot to set something? Or I'm just using it the wrong way...

Add these instructions for Nuxt support for vue-router-back-button

Hi, please add this to documentation :)

in ~/plugins/vue-router-back-button.js put:

import Vue from 'vue';
import { routerHistory, writeHistory } from 'vue-router-back-button';

Vue.use(routerHistory);

export default ({ app }) => {
  app.router.afterEach(writeHistory);
};

and add it to the plugins section of nuxt.config.js:

...
  plugins: [
    ...
    { mode: 'client', src: '~plugins/vue-router-back-button.js' },
    ...
  ],
...

also here's a nuxt component for a back button. This would work for normal vue-router if you change nuxt-link to router-link:

<template>
  <nuxt-link :to="to">
    &#8592; Back
  </nuxt-link>
</template>

<script>
export default {
  computed: {
    to() {
      if (this.client || !this.$routerHistory || !this.$routerHistory.hasPrevious()) {
        // probably ssr, or hasn't navigated yet.
        return { path: '/' };
      }
      return { path: this.$routerHistory.previous().path };
    },
  },
};
</script>

I'll do a PR to modify the docs, if you want me to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.