gpt4 book ai didi

vuepress - vuepress 更改 404 页面

转载 作者:行者123 更新时间:2023-12-04 13:02:42 26 4
gpt4 key购买 nike

是否可以在不弹出和更改整个主题的情况下更改/自定义 Vuepress 的 404 页面?

我目前正在使用 enhanceApp.js ,但我不确定如何更改路由器选项(catchall 路由),因为路由器已经创建。我现在让它工作的方式是这样的:

router.beforeEach((to, from, next) => {
if (to.matched.length > 0 && to.matched[0].path === "*") {
next("/404.html");
} else {
next();
}
});

然而,这感觉就像一个黑客,因为我总是重定向到包含我的 404 的自定义和现有页面。有没有更正式的方法来做到这一点?

最佳答案

我有一个基于 Vuepress 1.5.x 的站点,我能够简单地在主题/布局下创建一个名为 NotFound.vue 的页面。无需enhanceApp.js 更改。
Vuepress 本身似乎已经知道这个保留的布局名称,基于 code here .
我之前有一个名为 404.vue 的页面,但是我收到一条警告,说页面应该遵循正确的 HTML 5 组件命名标准。只需将其重命名为 NotFound.vue 即可。
我的 NotFound.vue 文件的内容:

<template>
<BaseLayout>
<template #content>
<v-container class="text-center">
<div class="py-6" />
<h1>Oops!</h1>
<p>Nothing to see here.</p>
<v-btn class="cyan--text text--darken-3"
exact :to="'/'" text>Go home</v-btn>
</v-container>
</template>
</BaseLayout>
</template>

<script>
export default {
name: "NotFound"
};
</script>

关于vuepress - vuepress 更改 404 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51702549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com