Update router.js: add option value 'routerPrefixForChangeableBase'

add  option value 'routerPrefixForChangeableBase' in router's options for this case:
The app deploy in the address: https://xxx/base1/routername/pagename.html, in this case, the base value may be '/base1/',
and i hope the address can also be visit at https://xxx/someSpePath/base1/routername/pagename.html,then routerPrefixForChangeableBase can be set '/routername'。the base value is too restrictive in some case. So, i hope fixed it.
This commit is contained in:
chenPengXu 2023-08-30 20:52:31 +08:00 committed by GitHub
parent b381000de6
commit cca6187639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,6 +90,7 @@ Vue.use(Router)
export const routerOptions = {
mode: '<%= router.mode %>',
base: '<%= router.base %>',
routerPrefixForChangeableBase: '<%= router.routerPrefixForChangeableBase %>',
linkActiveClass: '<%= router.linkActiveClass %>',
linkExactActiveClass: '<%= router.linkExactActiveClass %>',
scrollBehavior,
@ -102,7 +103,11 @@ export const routerOptions = {
}
export function createRouter (ssrContext, config) {
const base = (config._app && config._app.basePath) || routerOptions.base
let base = (config._app && config._app.basePath) || routerOptions.base
if (ssrContext === null && routerOptions.routerPrefixForChangeableBase) {
const path = decodeURI(window.location.pathname)
base = path.substring(0, path.indexOf(routerOptions.routerPrefixForChangeableBase) + 1)
}
const router = new Router({ ...routerOptions, base })
// TODO: remove in Nuxt 3