vue-router#createMemoryHistory TypeScript Examples
The following examples show how to use
vue-router#createMemoryHistory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: entry-server.ts From vite-ssr with MIT License | 5 votes |
viteSSR: SsrHandler = function viteSSR(
App,
{
routes,
base,
routerOptions = {},
pageProps = { passToPage: true },
...options
},
hook
) {
if (pageProps && pageProps.passToPage) {
addPagePropsGetterToRoutes(routes)
}
return coreViteSSR(options, async (context, { isRedirect, ...extra }) => {
const app = createApp(App)
const routeBase = base && withoutSuffix(base(context), '/')
const router = createRouter({
...routerOptions,
history: createMemoryHistory(routeBase),
routes: routes as RouteRecordRaw[],
})
router.beforeEach((to) => {
to.meta.state = extra.initialState || null
})
provideContext(app, context)
const fullPath = getFullPath(context.url, routeBase)
const { head } =
(hook &&
(await hook({
app,
router,
initialRoute: router.resolve(fullPath),
...context,
}))) ||
{}
app.use(router)
router.push(fullPath)
await router.isReady()
if (isRedirect()) return {}
Object.assign(
context.initialState || {},
(router.currentRoute.value.meta || {}).state || {}
)
const body = await renderToString(app, context)
if (isRedirect()) return {}
const {
headTags = '',
htmlAttrs = '',
bodyAttrs = '',
} = head ? renderHeadToString(head) : {}
return { body, headTags, htmlAttrs, bodyAttrs }
})
}
Example #2
Source File: index.ts From quasar-app-extension-http-authentication with MIT License | 5 votes |
export default function createRouter () {
return _createRouter({
// use appropriate history implementation for server/client
// import.meta.env.SSR is injected by Vite.
history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(),
routes
})
}