Skip to content

Commit f4c8487

Browse files
committed
feat: add dynamic routing and enhance button labels in localization
1 parent b868555 commit f4c8487

File tree

9 files changed

+106
-33
lines changed

9 files changed

+106
-33
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"dependencies": {
2828
"@iconify-json/carbon": "^1.2.4",
29+
"@iconify-json/logos": "^1.2.3",
2930
"@unhead/vue": "^1.11.14",
3031
"@unocss/reset": "^0.58.9",
3132
"@vueuse/core": "^10.11.1",

pnpm-lock.yaml

Lines changed: 23 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/layouts/page.vue

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,8 @@ const { t } = useI18n()
33
44
const { toggleLocale } = useLocale()
55
6-
const route = useRoute()
7-
8-
const router = useRouter()
9-
106
const { headerLogo } = storeToRefs(useLayoutStore())
117
12-
function goPage(path: string) {
13-
router.push(path)
14-
}
15-
168
function openGithub() {
179
window.open(GITHUB_URL)
1810
}
@@ -27,15 +19,6 @@ function openGithub() {
2719
<sup><i>v{{ APP_VERSION }}</i></sup>
2820
</h1>
2921
<div flex="~ wrap gap-2 justify-center">
30-
<TheButton v-if="route.path === '/about'" @click="goPage('/')">
31-
{{ t('button.index-page') }}
32-
</TheButton>
33-
<TheButton v-else @click="goPage('/about')">
34-
{{ t('button.about-page') }}
35-
</TheButton>
36-
<TheButton @click="goPage('/404')">
37-
{{ t('button.404-page') }}
38-
</TheButton>
3922
<TheButton @click="toggleLocale()">
4023
<i i-carbon-ibm-watson-language-translator />
4124
</TheButton>

src/locales/en.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
},
1818
"button": {
1919
"back": "Back",
20-
"index-page": "Index",
21-
"about-page": "About",
22-
"404-page": "404",
20+
"index-page": "Index Page",
21+
"about-page": "About Page",
22+
"404-page": "404 Page",
2323
"show-logo": "Show Logo",
2424
"hide-logo": "Hide Logo",
25-
"toggle-logo-description": "Toggle the visibility of the logo",
26-
"request": "Request"
25+
"toggle-logo-description": "State management based on Pinia",
26+
"axios-request": "Request with Axios",
27+
"dynamic-route": "Dynamic Route",
28+
"dynamic-route-description": "File-based dynamic routing"
2729
},
2830
"empty": "No content"
2931
}

src/locales/zh.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
"button": {
2020
"back": "返回",
2121
"index-page": "首页",
22-
"about-page": "关于",
23-
"404-page": "404",
22+
"about-page": "关于页面",
23+
"404-page": "404 页面",
2424
"show-logo": "显示 Logo",
2525
"hide-logo": "隐藏 Logo",
26-
"toggle-logo-description": "切换 Logo 的可见性",
27-
"request": "网络请求"
26+
"toggle-logo-description": "基于 Pinia 的状态管理",
27+
"axios-request": "使用 Axios 发起请求",
28+
"dynamic-route": "动态路由",
29+
"dynamic-route-description": "基于文件的动态路由"
2830
},
2931
"empty": "暂无内容"
3032
}

src/pages/dynamic/[id].vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<route lang="json">
2+
{
3+
"name": "dynamic",
4+
"meta": {
5+
"layout": "page"
6+
}
7+
}
8+
</route>
9+
10+
<script lang="ts" setup>
11+
const route = useRoute()
12+
13+
const title = computed(() => {
14+
return route.params.id
15+
})
16+
17+
useHead({
18+
title,
19+
})
20+
</script>
21+
22+
<template>
23+
<TheCard>
24+
<h2 text-center text-lg font-bold mb-5>
25+
Hi, {{ route.params.id }}
26+
</h2>
27+
<p>
28+
Read more about dynamic routing in the
29+
<a target="_blank" href="https://uvr.esm.is/guide/file-based-routing.html#dynamic-routes">
30+
https://uvr.esm.is/guide/file-based-routing.html#dynamic-routes
31+
</a>
32+
</p>
33+
</TheCard>
34+
</template>

src/pages/index.vue

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<script lang="ts" setup>
1111
import type { TodoList } from '@/types/todo'
1212
13+
const router = useRouter()
14+
1315
const { t } = useI18n()
1416
1517
const title = computed(() => {
@@ -42,20 +44,48 @@ function fetchData() {
4244
loading.value = false
4345
})
4446
}
47+
48+
function goPage(path: string) {
49+
router.push(path)
50+
}
51+
52+
function goDynamicRoute() {
53+
goPage(`/dynamic/${Math.random().toString().slice(2, 6)}`)
54+
}
4555
</script>
4656

4757
<template>
58+
<TheCard my-5>
59+
<div flex="~ items-center justify-center gap-2 wrap" mx-auto mb-5>
60+
<TheButton @click="goPage('/')">
61+
{{ t('button.index-page') }}
62+
</TheButton>
63+
<TheButton @click="goPage('/about')">
64+
{{ t('button.about-page') }}
65+
</TheButton>
66+
<TheButton @click="goPage('/404')">
67+
{{ t('button.404-page') }}
68+
</TheButton>
69+
<TheButton @click="goDynamicRoute">
70+
{{ t('button.dynamic-route') }}
71+
</TheButton>
72+
</div>
73+
<p>
74+
{{ t('button.dynamic-route-description') }}
75+
</p>
76+
</TheCard>
4877
<TheCard my-5>
4978
<TheButton mx-auto mb-5 @click="toggleLogo">
5079
{{ headerLogo ? t('button.hide-logo') : t('button.show-logo') }}
5180
</TheButton>
52-
<p>
53-
{{ t('button.toggle-logo-description') }}
81+
<p flex="~ items-center justify-center gap-2">
82+
<i i-logos-pinia />
83+
<span>{{ t('button.toggle-logo-description') }}</span>
5484
</p>
5585
</TheCard>
5686
<TheCard my-5>
5787
<TheButton mx-auto mb-5 :loading @click="fetchData">
58-
{{ t('button.request') }}
88+
{{ t('button.axios-request') }}
5989
</TheButton>
6090
<ul v-if="todoList && todoList.length > 0" w-full my-5 h-30 overflow-y-auto>
6191
<li v-for="item in todoList" :key="item.id">

src/styles/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ body {
1919
}
2020

2121
a {
22-
--at-apply: op-75 hover:op-100;
22+
--at-apply: dark:op-75 dark:hover:op-100 op-100 hover:op-75;
2323
text-decoration: underline;
2424
}
2525

typings/vue-router.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ declare module 'vue-router/auto-routes' {
2121
'index': RouteRecordInfo<'index', '/', Record<never, never>, Record<never, never>>,
2222
'not-found': RouteRecordInfo<'not-found', '/:path(.*)', { path: ParamValue<true> }, { path: ParamValue<false> }>,
2323
'about': RouteRecordInfo<'about', '/about', Record<never, never>, Record<never, never>>,
24+
'dynamic': RouteRecordInfo<'dynamic', '/dynamic/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
2425
}
2526
}

0 commit comments

Comments
 (0)