在 vuepress 中更改 404 页面
Change 404 page in vuepress
是否可以更改/自定义 Vuepress 的 404 页面而无需弹出并且不必更改整个主题?
我目前正在使用 enhanceApp.js
,但我不确定如何更改路由器选项(通用路由),因为路由器已经创建。我现在让它工作的方式是这样的:
router.beforeEach((to, from, next) => {
if (to.matched.length > 0 && to.matched[0].path === "*") {
next("/404.html");
} else {
next();
}
});
但是,这感觉像是一个 hack,因为我总是重定向到包含我的 404 的自定义和现有页面。有没有更正式的方法来做到这一点?
我有一个基于 Vuepress 1.5.x 的站点,我能够简单地在 theme/layouts 下创建一个名为 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 的 404 页面而无需弹出并且不必更改整个主题?
我目前正在使用 enhanceApp.js
,但我不确定如何更改路由器选项(通用路由),因为路由器已经创建。我现在让它工作的方式是这样的:
router.beforeEach((to, from, next) => {
if (to.matched.length > 0 && to.matched[0].path === "*") {
next("/404.html");
} else {
next();
}
});
但是,这感觉像是一个 hack,因为我总是重定向到包含我的 404 的自定义和现有页面。有没有更正式的方法来做到这一点?
我有一个基于 Vuepress 1.5.x 的站点,我能够简单地在 theme/layouts 下创建一个名为 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>