diff --git a/src/components/cards/Card.vue b/src/components/cards/Card.vue index 47b87ab..310b0a2 100644 --- a/src/components/cards/Card.vue +++ b/src/components/cards/Card.vue @@ -29,7 +29,7 @@ let { card, idx } = defineProps<{ function getRealHref(href: string, user_name: string = "$") { if (href.startsWith('$')) { - href = `/card/${user_name}${href.substring(1)}`; + href = `/card${href.substring(1)}?user_name=${user_name}`; } return href; } diff --git a/src/router/card.ts b/src/router/card.ts index 19922f4..f924e4b 100644 --- a/src/router/card.ts +++ b/src/router/card.ts @@ -1,30 +1,31 @@ import { type RouteRecordRaw } from "vue-router"; import { file_api } from "./config.json"; -export function getCardUrl(path: string = file_api.cards.home): string { - return `${file_api.root_url}/` + - `${file_api.cards.url}/` + - `${path}?` + - `type=${file_api.cards.type}` +export function getCardUrl(path: string = file_api.cards.home, query: Record = {}): string { + const url = new URL(window.location.origin); + url.pathname = `${file_api.root_url}/${file_api.cards.url}/${path}`; + + url.searchParams.set('type', file_api.cards.type); + Object.entries(query).forEach(([key, value]) => { + url.searchParams.set(key, value); + }) + return url.toString(); }; export default function cardRoute(): RouteRecordRaw { return { name: "cardShower", - path: "/card/:user_name/:pages_path*", + path: "/card/:pages_path*", component: () => import("@/pages/CardsShower.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; - } + const path = Array.isArray(to.params.pages_path) + ? to.params.pages_path.join("/") + : to.params.pages_path; return { ...to.params, path, - url: getCardUrl(path), + url: getCardUrl(path, to.query as Record), } }, } diff --git a/src/router/index.ts b/src/router/index.ts index 4b65e2b..9e2bffd 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -26,7 +26,7 @@ const router = createRouter({ component: () => import("@/pages/Users.vue"), }, cardRoute(), - noteRoute(), + // noteRoute(), // { // name: "noteShower", // path: "/note/:note_name/:token?", diff --git a/src/router/note.ts b/src/router/note.ts index 8bfc6e6..11b8230 100644 --- a/src/router/note.ts +++ b/src/router/note.ts @@ -1,11 +1,15 @@ 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 function getNoteUrl(path: string = file_api.cards.home, query: Record = {}): string { + const url = new URL(window.location.origin); + url.pathname = `${file_api.root_url}/${file_api.notes.url}/${path}`; + + url.searchParams.set('type', file_api.notes.type); + Object.entries(query).forEach(([key, value]) => { + url.searchParams.set(key, value); + }) + return url.toString(); }; export default function noteRoute(): RouteRecordRaw { @@ -14,18 +18,15 @@ export default function noteRoute(): RouteRecordRaw { 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; - } + const path = Array.isArray(to.params.pages_path) + ? to.params.pages_path.join("/") + : to.params.pages_path; return { ...to.params, path, - url: getNoteUrl(path), + url: getNoteUrl(path, to.query as Record), } }, } -} +} \ No newline at end of file