vuejs / vuepress

📝 Minimalistic Vue-powered static site generator
https://vuepress.vuejs.org
MIT License
22.45k stars 4.78k forks source link

Is there any way to change mode like 'hash', 'history' in vuepress #2468

Open RayKimEX opened 4 years ago

RayKimEX commented 4 years ago

Feature request

Asked Stackoverflow

but not answered yet until now

What problem does this feature solve?

I want to change mode 'history' to 'hash' in vuepress

What does the proposed API look like?

I think this feature could be in config.js

like

themeConfig: {
   locationMode : 'hash',
   ...
}

How should this be implemented in your opinion?

Some user would definitely want to change LocationStrategy like history or hash

Are you willing to work on this yourself?

No

RayKimEX commented 4 years ago

What is the reason of no responding?

TheGreenToaster commented 3 years ago

I was able to change the router to hash mode with the following enhanceApp.js

export default ({
    Vue, // the version of Vue being used in the VuePress app
    options, // the options for the root Vue instance
    router, // the router instance for the app
    siteData, // site metadata
    isServer // is this enhancement applied in server-rendering or client
  }) => {
    // ...apply enhancements to the app
    var VueRouter = require('vue-router').default;
    router = new VueRouter({
        routes: router.options.routes,
        base: router.options.base,
        fallback: router.options.fallback,
        scrollBehavior: router.options.scrollBehavior,
        mode: 'hash'
    });
  }

While it did work it unveiled a larger problem with moving to hash based routing. The links that are created for the headers already make use of the hash also the existing links do not contain a hash breaking the navigation.