Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Create static 404 page
Browse files Browse the repository at this point in the history
This requires disabling subfolders in the nuxt generate config and then creating a 404 page.
  • Loading branch information
JacobSNGoodwin committed Mar 21, 2019
1 parent 439d4f2 commit e7f8bd5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
9 changes: 5 additions & 4 deletions layouts/error.vue
@@ -1,21 +1,22 @@
<template>
<div class="container">
<div class="error-container">
<h1 v-if="error.statusCode === 404" class="title is-1 has-text-centered">
Page not found
</h1>
<h1 v-else class="title is-1 has-text-centered">
An error occurred
</h1>
<div class="buttons is-centered">
<nuxt-link to="/" tag="button" class="button is-info">
Home page
<nuxt-link to="/" tag="a" class="button is-info">
Home
</nuxt-link>
</div>
</div>
</template>

<script>
export default {
name: 'ErrorPage',
props: {
error: {
type: Object,
Expand All @@ -26,7 +27,7 @@ export default {
</script>

<style scoped>
.container {
.error-container {
margin-top: 2em;
margin-bottom: 2em;
}
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.js
Expand Up @@ -62,7 +62,7 @@ export default {
* Generate dynamic routes for static site generations
*/
generate: {
fallback: true,
subFolders: false,
routes: generateRoutes
},
/*
Expand Down
31 changes: 31 additions & 0 deletions pages/404.vue
@@ -0,0 +1,31 @@
<template>
<div class="error-container">
<h1 class="title is-1 has-text-centered">
Page not found
</h1>
<div class="buttons is-centered">
<nuxt-link to="/" tag="a" class="button is-info">
Home
</nuxt-link>
</div>
</div>
</template>

<script>
export default {
name: 'ErrorPage',
props: {
error: {
type: Object,
default: null
}
}
}
</script>

<style scoped>
.error-container {
margin-top: 2em;
margin-bottom: 2em;
}
</style>
10 changes: 4 additions & 6 deletions store/index.js
Expand Up @@ -36,14 +36,14 @@ export const actions = {
async nuxtServerInit({ commit }) {
// get site settings, and whether or not posts have a previous or next post
// use this for both static and universal apps
const settings = await ghostAPI().settings.browse()
const tags = await ghostAPI().tags.browse({ limit: 'all' })
const authors = await ghostAPI().authors.browse({ limit: 'all' })
const posts = await ghostAPI().posts.browse({
limit: 'all',
fields: 'slug,title'
})

const tags = await ghostAPI().tags.browse({ limit: 'all' })
const authors = await ghostAPI().authors.browse({ limit: 'all' })

// append next and previous slugs (for links in a post) to next and previous posts
const postsWithLinks = posts.map((post, index) => {
const prevSlug = posts[index - 1] ? posts[index - 1].slug : null
Expand All @@ -56,12 +56,10 @@ export const actions = {
}
})

const settings = await ghostAPI().settings.browse()

commit('setPostNav', postsWithLinks)
commit('setSiteSettings', settings)
commit('setSiteTags', tags)
commit('setSiteAuthors', authors)
commit('setPostNav', postsWithLinks)
},
async getIndexPosts({ commit }, pagination) {
// set desired fields for index lists (and tags/authors indices)
Expand Down
10 changes: 10 additions & 0 deletions util/ghost.js
Expand Up @@ -34,6 +34,16 @@ const generateRoutes = async () => {
// initialize array of routes to be filled
const routes = []

/*
** 404 page with access to site settings for navigation
*/

const settings = await api.settings.browse()
routes.push({
route: '/404',
payload: settings
})

/*
*
* Create post index pages (with only subset of post data)
Expand Down

0 comments on commit e7f8bd5

Please sign in to comment.