Skip to content

Commit

Permalink
feat: add 404 mode to router
Browse files Browse the repository at this point in the history
  • Loading branch information
50l3r committed Jan 23, 2025
1 parent 57c3d4f commit 78f9102
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kodama-ui",
"version": "0.35.3",
"version": "0.37.0",
"description": "Kodama UI is a Vue 3 component library that provides a set of components & funcionality to build your application.",
"homepage": "https://50l3r.github.io/kodama-ui",
"keywords": [
Expand Down
23 changes: 16 additions & 7 deletions src/config/_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import {
createRouter,
createWebHashHistory,
RouteRecordRaw,
NavigationGuardWithThis
NavigationGuardWithThis,
createWebHistory
} from 'vue-router'

export default (
app: App<Element>,
frontendRoutes: Array<RouteRecordRaw>,
beforeEach?: NavigationGuardWithThis<undefined>
beforeEach?: NavigationGuardWithThis<undefined>,
historyMode: 'hash' | 'web' = 'hash',
on404 = '/404'
) => {
const systemRoutes = [
{
Expand Down Expand Up @@ -92,15 +95,21 @@ export default (
title: 'Error interno',
public: true
}
},
{
path: '/:pathMatch(.*)*',
redirect: '/404'
}
]

if (on404) {
routes.push({
path: '/:pathMatch(.*)*',
redirect: on404
})
}

const router = createRouter({
history: createWebHashHistory(),
history:
historyMode === 'hash'
? createWebHashHistory()
: createWebHistory(),
routes
})

Expand Down
10 changes: 9 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type KodamaParams = {
router: {
routes: Array<RouteRecordRaw>
beforeEach?: NavigationGuardWithThis<undefined>
mode?: 'hash' | 'web'
route404?: string
}
components: Record<string, { [key: string]: any }>
menu: () => Menu[]
Expand Down Expand Up @@ -62,7 +64,13 @@ export function init(params: KodamaParams, app?: App<Element>) {
)

// App Routes
router(app, params.router.routes, params.router.beforeEach)
router(
app,
params.router.routes,
params.router.beforeEach,
params.router.mode,
params.router.route404
)

// App Components
components(app, params.components)
Expand Down

0 comments on commit 78f9102

Please sign in to comment.