fix(generator): handle when no routes.json defined (#8166)

This commit is contained in:
Sébastien Chopin 2020-10-08 16:29:30 +02:00 committed by GitHub
parent dfaa1960f7
commit 34f32113b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -48,7 +48,7 @@ export default {
watch: { watch: {
async '$route.query.page' (page) { async '$route.query.page' (page) {
this.$nuxt.$loading.start() this.$nuxt.$loading.start()
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`) const data = await fetch(`https://reqres.in/api/users?page=${page}`).then(res => res.json())
this.users = data.data this.users = data.data
this.transitionName = this.getTransitionName(page) this.transitionName = this.getTransitionName(page)
this.page = +(page || 1) this.page = +(page || 1)

View File

@ -104,7 +104,13 @@ export default class Generator {
if (this.options.router.mode === 'hash') { if (this.options.router.mode === 'hash') {
routes = ['/'] routes = ['/']
} else { } else {
try {
routes = flatRoutes(this.getAppRoutes()) routes = flatRoutes(this.getAppRoutes())
} catch (err) {
// Case: where we use custom router.js
// https://github.com/nuxt-community/router-module/issues/83
routes = ['/']
}
} }
routes = routes.filter(route => this.shouldGenerateRoute(route)) routes = routes.filter(route => this.shouldGenerateRoute(route))
routes = this.decorateWithPayloads(routes, generateRoutes) routes = this.decorateWithPayloads(routes, generateRoutes)