-
-
Notifications
You must be signed in to change notification settings - Fork 932
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
How to use hash history instead of browser history? #102
Comments
Please read the docs for vue-router-next, ViteSSG bypass your configure to it via the second args |
what is "the second args"? vite defineConfig? didn't find any router related args in vite.config.ts |
OK I found it in main.ts |
This works only on dev mode.
I noticed that
|
@moh1434 I have the same result when I build. Did you find a solution for that in between ? |
// eslint-disable-next-line import/order
import { modules } from './importModules'
import type { ViteSSGContext } from 'vite-ssg'
import { ViteSSG } from 'vite-ssg'
import generatedRoutes from 'virtual:generated-pages'
import { setupLayouts } from 'layouts-generated'
import { createWebHashHistory } from 'vue-router'
import 'default-passive-events'
import App from './App.vue'
const routes = setupLayouts(generatedRoutes)
// https://github.com/antfu/vite-ssg
// noinspection JSUnusedGlobalSymbols
export const createApp = ViteSSG(
App,
// {routes, history: undefined} will cause 'location is undefined' error with ssr
import.meta.env.VITE_APP_SSR ? { routes } : { routes, history: createWebHashHistory() },
(ctx) => {
Object.entries(modules).forEach(([k, v]: [string, any]) => {
if (import.meta.env.DEV) console.debug(`imported module ${k}:`, v)
share(k, registerModule(ctx, v))
})
function getModuleName(key: string) {
const p2 = key.lastIndexOf('.')
return p2 < 0 ? key.substring(10) : key.substring(10, p2) // length of './modules/' is 10
}
function registerModule(context: ViteSSGContext, module: Record<string, Record<string, any>>) {
const exported = module.default
if (typeof exported === 'function') {
const plugin = exported(context)
if (typeof plugin === 'function' || typeof plugin?.install === 'function') context.app.use(plugin)
return plugin
}
}
function share(key: string, module: any) {
if (module !== undefined) window.shared[getModuleName(key)] = module
}
window.shared.app = ctx.app
},
) importModules.ts:
|
No description provided.
The text was updated successfully, but these errors were encountered: