Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 77393a2

Browse files
committed
fix(playground): resolve 404 routes to home
1 parent b02240b commit 77393a2

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
"scaffold": "hygen",
1616
"playground:routes": "ts-node ./scripts/parse-routes.ts",
17-
"playground": "yarn playground:routes && vite serve playground",
18-
"playground:build": "yarn build && yarn playground:routes && vite build playground",
17+
"playground": "yarn playground:routes && NODE_ENV=development vite serve playground",
18+
"playground:build": "yarn build && yarn playground:routes && NODE_ENV=production vite build playground",
1919

2020
"c-alert": "yarn workspace @chakra-ui/c-alert",
2121
"c-box": "yarn workspace @chakra-ui/c-box",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div>
3+
</div>
4+
</template>
5+
6+
<script lang="ts">
7+
import { defineComponent } from "vue";
8+
9+
export default defineComponent({
10+
mounted() {
11+
this.$router.push('/')
12+
}
13+
})
14+
</script>

playground/src/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function buildRoutes(routes) {
1919

2020
const routes = buildRoutes(generatedRoutes)
2121

22+
console.log(routes)
23+
2224
export default createRouter({
2325
history: createWebHistory(),
2426
routes,

scripts/parse-routes.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const flatten = (routes: Route[], resolver: Resolver): Array<string> => {
7171

7272
const baseRoutes = getBaseRoutes()
7373

74+
const NotFoundRoute: Route = {
75+
name: 'NotFound',
76+
path: '*',
77+
component: '../components/Home.vue',
78+
}
79+
7480
const routes: Route[] = [
7581
{
7682
name: 'Home',
@@ -93,6 +99,9 @@ baseRoutes.map((basePath) => {
9399
routes.push(componentRoute)
94100
})
95101

102+
// 404 Route
103+
routes.push(NotFoundRoute)
104+
96105
fs.writeFileSync(
97106
path.join(playgroundRoot, './.generated/routes.json'),
98107
JSON.stringify(routes, null, 2),
@@ -129,7 +138,7 @@ fs.writeFileSync(
129138
`/* Package components resolver only used in development mode */
130139
module.exports = {\n${baseRoutes
131140
.map(
132-
(pkg) => ` '@chakra-iu/${pkg}': '${packagesRoot}/${pkg}/src/index.ts'`
141+
(pkg) => ` '@chakra-ui/${pkg}': '${packagesRoot}/${pkg}/src/index.ts'`
133142
)
134143
.join(',\n')}\n}`,
135144
'utf8'

vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const ChakraPlaygroundPlugin = ({ app }) => {
2525

2626
const __DEV__ = process.env.NODE_ENV !== 'production'
2727

28+
console.log({ __DEV__ }, process.env.NODE_ENV)
29+
2830
createServer({
2931
alias: {
3032
...(!__DEV__ && { ['@chakra-ui']: path.resolve(__dirname, './packages') }),

0 commit comments

Comments
 (0)