-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
42 lines (38 loc) · 952 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export function createRouter(
ssrContext,
createDefaultRouter,
routerOptions,
config
) {
if (process.server) {
config._app.theme = ssrContext?.req?.theme
}
const options =
routerOptions || createDefaultRouter(ssrContext, config).options
return new Router({
...options,
routes: fixRoutes(
options.routes,
ssrContext?.req?.theme || config._app.theme
),
})
}
function fixRoutes(defaultRoutes, theme) {
return defaultRoutes
.filter((route) => route.path.includes(theme))
.map((route) => {
const isIndex = route.path === `/${theme}`
const isIndexTranslated = route.path.split(`/${theme}`)[1] === ''
return {
...route,
path: isIndex
? '/'
: isIndexTranslated
? route.path.split(`/${theme}`)[0]
: route.path.replace(`/${theme}`, ''),
}
})
}