mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Merge pull request #3030 from williamchong007/dev
Add redirect support in extendRoutes
This commit is contained in:
commit
298c386213
@ -7,8 +7,9 @@ import Router from 'vue-router'
|
||||
route._name = '_' + hash(route.component)
|
||||
components.push({ _name: route._name, component: route.component, name: route.name, chunkName: route.chunkName })
|
||||
res += tab + '{\n'
|
||||
res += tab + '\tpath: ' + JSON.stringify(route.path) + ',\n'
|
||||
res += tab + '\tcomponent: ' + (splitPages ? route._name : `() => ${route._name}.default || ${route._name}`)
|
||||
res += tab + '\tpath: ' + JSON.stringify(route.path)
|
||||
res += (route.component) ? ',\n\t' + tab + 'component: ' + (splitPages ? route._name : `() => ${route._name}.default || ${route._name}`) : ''
|
||||
res += (route.redirect) ? ',\n\t' + tab + 'redirect: ' + JSON.stringify(route.redirect) : ''
|
||||
res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : ''
|
||||
res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t', components) + '\n\t' + tab + ']' : ''
|
||||
res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n')
|
||||
@ -18,6 +19,7 @@ import Router from 'vue-router'
|
||||
const _components = []
|
||||
const _routes = recursiveRoutes(router.routes, '\t\t', _components)
|
||||
%><%= uniqBy(_components, '_name').map((route) => {
|
||||
if (!route.component) return ''
|
||||
const path = relativeToBuild(route.component)
|
||||
const chunkName = wChunk(route.chunkName)
|
||||
const name = route._name
|
||||
|
4
test/fixtures/with-config/nuxt.config.js
vendored
4
test/fixtures/with-config/nuxt.config.js
vendored
@ -12,6 +12,10 @@ module.exports = {
|
||||
name: 'about-bis',
|
||||
path: '/about-bis',
|
||||
component: '~/pages/about.vue'
|
||||
},
|
||||
{
|
||||
path: '/redirect/about-bis',
|
||||
redirect: '/about-bis'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -171,6 +171,21 @@ test.serial('/test/about-bis (added with extendRoutes)', async t => {
|
||||
t.true(html.includes('<h1>About page</h1>'))
|
||||
})
|
||||
|
||||
test.serial('/test/redirect/about-bis (redirect with extendRoutes)', async t => {
|
||||
const logSpy = await interceptLog()
|
||||
const window = await nuxt.renderAndGetWindow(url('/test/redirect/about-bis'))
|
||||
t.true(logSpy.calledOnce)
|
||||
t.is(logSpy.args[0][0], 'Test plugin!')
|
||||
release()
|
||||
|
||||
const windowHref = window.location.href
|
||||
t.true(windowHref.includes('/test/about-bis'))
|
||||
|
||||
const html = window.document.body.innerHTML
|
||||
t.true(html.includes('<h1>Custom layout</h1>'))
|
||||
t.true(html.includes('<h1>About page</h1>'))
|
||||
})
|
||||
|
||||
test('Check stats.json generated by build.analyze', t => {
|
||||
const stats = require(resolve(
|
||||
__dirname,
|
||||
|
Loading…
Reference in New Issue
Block a user