refactor(NoteShower): 使用路径和URL属性替换note_name和token

在NoteShower组件中,props从['note_name', 'token']被修改为['path', 'url']以更好地与路由配置对齐。这一改变是为了适应新的路由结构,其中note_name和token已被弃用,并被包含在props路由参数中。

refactor(router): 添加noteRoute命名空间并移除NoteShower路由配置

从主路由配置中移除独立的NoteShower路由,并将其移至新的noteRoute命名空间下。此更改实现了路由配置的模块化,使notes相关路由能够在一个独立的命名空间内进行管理和维护。
This commit is contained in:
ZZY 2024-09-01 23:48:22 +08:00
parent f4d7e959ae
commit 3325d5aacc
3 changed files with 46 additions and 13 deletions

View File

@ -7,10 +7,10 @@ import FetchWrapper from "@/components/utils/FetchWapper";
import { file_api } from '@/router/config.json'; import { file_api } from '@/router/config.json';
const props = defineProps(['note_name', 'token']) const props = defineProps(['path', 'url'])
onMounted(() => { onMounted(() => {
FetchWrapper.fetch(`${file_api.root_url}/${file_api.notes.url}/${props.note_name}?type=${file_api.notes.type}`, FetchWrapper.fetch(props.url,
{ {
timeout: 3000, timeout: 3000,
headers: { headers: {

View File

@ -1,5 +1,6 @@
import { createRouter, createWebHistory } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
import cardRoute from "./card"; import cardRoute from "./card";
import noteRoute from "./note";
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
@ -25,17 +26,18 @@ const router = createRouter({
component: () => import("@/pages/Users.vue"), component: () => import("@/pages/Users.vue"),
}, },
cardRoute(), cardRoute(),
{ noteRoute(),
name: "noteShower", // {
path: "/note/:note_name/:token?", // name: "noteShower",
component: () => import("@/pages/NoteShower.vue"), // path: "/note/:note_name/:token?",
props: true, // component: () => import("@/pages/NoteShower.vue"),
// props(route) { // props: true,
// return { // // props(route) {
// ...route.params // // return {
// } // // ...route.params
// }, // // }
}, // // },
// },
{ {
name: 'notFound', name: 'notFound',
path: "/:any*", // 使用正则表达式匹配所有路径 path: "/:any*", // 使用正则表达式匹配所有路径

31
src/router/note.ts Normal file
View File

@ -0,0 +1,31 @@
import { type RouteRecordRaw } from "vue-router";
import { file_api } from "./config.json";
export function getNoteUrl(path: string = file_api.cards.home): string {
return `${file_api.root_url}/` +
`${file_api.notes.url}/` +
`${path}?` +
`type=${file_api.notes.type}`
};
export default function noteRoute(): RouteRecordRaw {
return {
name: "cardShower",
path: "/note/:pages_path*",
component: () => import("@/pages/NoteShower.vue"),
props(to) {
let path: string;
if (Array.isArray(to.params.pages_path)) {
path = to.params.pages_path.join("/");
} else {
path = to.params.pages_path;
}
return {
...to.params,
path,
url: getNoteUrl(path),
}
},
}
}