Skip to content

Commit

Permalink
Update router
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Apr 20, 2023
1 parent 7da9b8c commit 138ebf2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
7 changes: 3 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fileURLToPath } from 'node:url'
import express from 'express'
import { generateConsoleMessage } from './src/ssr/utils/generateConsoleMessage.js'


const isTest = process.env.VITEST

export async function createServer(
Expand Down Expand Up @@ -103,10 +102,10 @@ if (!isTest) {
createServer().then(({ app }) =>
app.listen(6173, () => {
generateConsoleMessage({ port: 6173, url: 'http://localhost' })
})
)
})
)
}

function makeAppContainer(app = '') {
return `<div id="app">${app}</div>`
}
}
25 changes: 17 additions & 8 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,36 @@ import {
import dynamicRoutes from '~pages'

const coreModuleRoutes = import.meta.glob('@/modules/**/router/*.js', {
import: 'default', eager: true
import: 'default',
eager: true
})
const userModuleRoutes = import.meta.glob('#/modules/**/router/*.js', {
import: 'default', eager: true
import: 'default',
eager: true
})

const { base_url, hash_mode } = __APP_ENV__

const moduleRoutes = [].concat(
...Object.values(coreModuleRoutes),
...Object.values(userModuleRoutes)
)

const { base_url, hash_mode } = __APP_ENV__

export const routes = [...dynamicRoutes, ...moduleRoutes]

function getHistory() {
if (import.meta.env.SSR) {
return createMemoryHistory(base_url)
} else if (hash_mode) {
return createWebHashHistory(base_url)
} else {
return createWebHistory(base_url)
}
}

export function createRouter() {
return _createRouter({
history: import.meta.env.SSR
? createMemoryHistory('/')
: createWebHistory(base_url),

history: getHistory(),
routes
})
}

0 comments on commit 138ebf2

Please sign in to comment.