Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file path is lost when opening a html file directly in browser #163

Closed
mika76 opened this issue Apr 8, 2020 · 3 comments
Closed

file path is lost when opening a html file directly in browser #163

mika76 opened this issue Apr 8, 2020 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@mika76
Copy link

mika76 commented Apr 8, 2020

I have the following router...

const routerHistory = createWebHashHistory();

const router = createRouter({
  history: routerHistory,
  routes: [
    { path: "/", component: viewDashboard },
    { path: "/home", redirect: "/" },
    { path: "/params", component: viewParameters },
    // ....
  ],
  scrollBehavior(to, from, savedPosition) {
    return { x: 0, y: 0 };
  },
});

It works well if served from a http-serve or web server or whatever - but if the dist file is opened as a file:///...path...to../index.html directly in the browser, the route automatically changes to file:///#/ losing the whole file path and name.

@posva
Copy link
Member

posva commented Apr 9, 2020

This is indeed a problem. The current usage of hash history assumes a web server and uses the History API with a base of /# but that won't work on file:///. I will have to investigate that more but for the moment using a Web History with a base of # makes it work:

const routerHistory = createWebHistory('#')

@posva posva added the help wanted Extra attention is needed label Apr 9, 2020
@mika76
Copy link
Author

mika76 commented Apr 9, 2020

Thanks for the workaround - it works for the moment. It has the hilarious side effect of appending /# on each refresh 🤣

@posva posva closed this as completed in 760d216 Apr 13, 2020
@mika76
Copy link
Author

mika76 commented Apr 14, 2020

Hey @posva think you could create an npm alpha release so I can play with this fix please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants