1
0
mirror of https://github.com/sendevia/website.git synced 2026-03-05 23:32:45 +08:00

refactor: redirection logic and add 404 page title handling

This commit is contained in:
2025-12-12 16:29:38 +08:00
parent d50be81c19
commit b40d6bffa4
3 changed files with 18 additions and 17 deletions

View File

@@ -23,12 +23,13 @@ export default {
enhanceApp({ app }) {
app.use(pinia);
app.component("MainLayout", Layout);
app.component("AppBar", AppBar);
app.component("ArticleMasonry", ArticleMasonry);
app.component("Footer", Footer);
app.component("Header", Header);
app.component("ImageViewer", ImageViewer);
app.component("MainLayout", Layout);
app.component("MaterialButton", Button);
app.component("MaterialCard", Card);
app.component("NavBar", NavBar);

View File

@@ -18,8 +18,6 @@ const currentRoutePath = ref(route.path);
const pendingRoutePath = ref<string | null>(null);
const isRedirecting = ref(false);
let redirectTimer: ReturnType<typeof setTimeout> | null = null;
/**
* 检查并执行重定向
* 返回 true 表示正在处理重定向
@@ -40,11 +38,9 @@ function checkAndRedirect(path: string): boolean {
document.title = `跳转中 | ${site.value.title}`;
}
redirectTimer = setTimeout(() => {
if (isClient()) {
window.location.replace(post.url);
}
}, 100);
if (isClient()) {
window.location.replace(post.url);
}
return true;
}
@@ -107,10 +103,6 @@ watch(
// 如果之前是重定向状态,清理状态
if (isRedirecting.value) {
isRedirecting.value = false;
if (redirectTimer) {
clearTimeout(redirectTimer);
redirectTimer = null;
}
}
if (newPath !== oldPath && !isTransitioning.value && oldPath !== undefined) {
@@ -145,11 +137,7 @@ if (isClient()) {
<template>
<div class="MainLayout">
<div v-if="isRedirecting">
<h1>Redirecting...</h1>
</div>
<template v-else>
<template v-if="!isRedirecting">
<NavBar />
<AppBar />
<Transition name="layout" mode="out-in" @before-leave="onBeforeLeave" @after-enter="onAfterEnter">

View File

@@ -1,3 +1,15 @@
<script setup lang="ts">
import { onBeforeMount, onMounted } from "vue";
onBeforeMount(() => {
document.title = "";
});
onMounted(() => {
document.title = "404";
});
</script>
<template>
<div class="notfound">
<div id="notfound-information">