Skip to content

Edge case: the location bounce back after installing router instance to instance of Vue #2584

@Azurewarth0920

Description

@Azurewarth0920

Reproduction

https://codesandbox.io/s/modern-resonance-fmxl4t

Steps to reproduce the bug

import { createApp } from "vue";
import App from "./App.vue";
import { router } from "./router";

const app = createApp(App).use(router); // Asynchronously bounce back to the URL when router instance created .
window.history.replaceState({}, "", "/foo"); // Doesn't work, router doesn't take it into account.
app.mount("#app");
window.history.replaceState({}, "", "/bar"); // Doesn't work, router doesn't take it into account.

Expected behavior

....
const app = createApp(App).use(router);
window.history.replaceState({}, "", "/foo"); // Finally will navigate to /foo
app.mount("#app");

and

....
const app = createApp(App).use(router);
app.mount("#app");
window.history.replaceState({}, "", "/bar"); // Finally will navigate to /bar

Actual behavior

...
const app = createApp(App).use(router); // navigate to the URL when router instance created asynchronously.
window.history.replaceState({}, "", "/foo"); // Doesn't work.
app.mount("#app");
window.history.replaceState({}, "", "/bar"); // Doesn't work.

Additional information

The behavior of installing router to instance of Vue is not intuitive.

After building the router instance by calling the createRouter, the URL will be saved into routerHistory, and it will be pushed when installing to instance of Vue asynchronously, even if the routerHistory is stale. (E.g the location is modified when install)

Somehow I think we should use the current browser location when installing the router instance, and this behavior is more intuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions