Skip to content

Commit

Permalink
fix: Don't try to process routes with no component
Browse files Browse the repository at this point in the history
Since routes with no component (like routes just existing to act as
a redirect) would cause a crash, don't try to process them.
  • Loading branch information
madmod authored and rchl committed Sep 10, 2019
1 parent 275df70 commit a53e32a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/helpers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ exports.makeRoutes = (baseRoutes, {
const routes = []
let pageOptions

// Skip route if it is only a redirect without a component.
if (route.redirect && !route.component) {
return route
}

// Extract i18n options from page
if (parsePages) {
pageOptions = extractComponentOptions(route.component)
Expand Down
16 changes: 15 additions & 1 deletion test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ describe('basic', () => {
let nuxt

beforeAll(async () => {
nuxt = (await setup(loadConfig(__dirname, 'basic'))).nuxt
const override = {
router: {
extendRoutes (routes) {
routes.push({ path: '/about', redirect: '/about-us' })
}
}
}

nuxt = (await setup(loadConfig(__dirname, 'basic', override, { merge: true }))).nuxt
})

afterAll(async () => {
Expand Down Expand Up @@ -126,6 +134,12 @@ describe('basic', () => {
const newRoute = window.$nuxt.localePath('about')
expect(newRoute).toBe('/about-us')
})

test('redirects to existing route', async () => {
const window = await nuxt.renderAndGetWindow(url('/about'))
const newRoute = window.$nuxt.switchLocalePath()
expect(newRoute).toBe('/about-us')
})
})

describe('lazy loading', () => {
Expand Down

0 comments on commit a53e32a

Please sign in to comment.