mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Fix page loader page normalization issue (#1844)
* Add integration tests for nested componentDidMount * Fix the page loader normalization issue. * Fix a typo in the url.
This commit is contained in:
parent
2e7bc1074d
commit
f578089d05
|
@ -19,7 +19,8 @@ export default class PageLoader {
|
|||
throw new Error('Route name should start with a "/"')
|
||||
}
|
||||
|
||||
return route.replace(/index$/, '')
|
||||
if (route === '/') return route
|
||||
return route.replace(/index$/, '').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
loadPage (route) {
|
||||
|
|
19
test/integration/basic/lib/cdm.js
Normal file
19
test/integration/basic/lib/cdm.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import React, {Component} from 'react'
|
||||
|
||||
export default class extends Component {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
mounted: false
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.setState({mounted: true})
|
||||
}
|
||||
|
||||
render () {
|
||||
return <p>ComponentDidMount {this.state.mounted ? 'executed on client' : 'not executed'}.</p>
|
||||
}
|
||||
}
|
2
test/integration/basic/pages/nested-cdm/index.js
Normal file
2
test/integration/basic/pages/nested-cdm/index.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
import CDM from '../../lib/cdm'
|
||||
export default CDM
|
2
test/integration/basic/pages/with-cdm.js
Normal file
2
test/integration/basic/pages/with-cdm.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
import CDM from '../lib/cdm'
|
||||
export default CDM
|
|
@ -321,5 +321,31 @@ export default (context, render) => {
|
|||
browser.close()
|
||||
})
|
||||
})
|
||||
|
||||
describe('with different types of urls', () => {
|
||||
it('on normal page', async () => {
|
||||
const browser = await webdriver(context.appPort, '/with-cdm')
|
||||
const text = await browser.elementByCss('p').text()
|
||||
|
||||
expect(text).toBe('ComponentDidMount executed on client.')
|
||||
browser.close()
|
||||
})
|
||||
|
||||
it('on dir/index page ', async () => {
|
||||
const browser = await webdriver(context.appPort, '/nested-cdm/index')
|
||||
const text = await browser.elementByCss('p').text()
|
||||
|
||||
expect(text).toBe('ComponentDidMount executed on client.')
|
||||
browser.close()
|
||||
})
|
||||
|
||||
it('on dir/ page ', async () => {
|
||||
const browser = await webdriver(context.appPort, '/nested-cdm/')
|
||||
const text = await browser.elementByCss('p').text()
|
||||
|
||||
expect(text).toBe('ComponentDidMount executed on client.')
|
||||
browser.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ describe('Basic Features', () => {
|
|||
renderViaHTTP(context.appPort, '/stateful'),
|
||||
renderViaHTTP(context.appPort, '/stateless'),
|
||||
renderViaHTTP(context.appPort, '/styled-jsx'),
|
||||
renderViaHTTP(context.appPort, '/with-cdm'),
|
||||
|
||||
renderViaHTTP(context.appPort, '/nav'),
|
||||
renderViaHTTP(context.appPort, '/nav/about'),
|
||||
|
@ -49,7 +50,9 @@ describe('Basic Features', () => {
|
|||
renderViaHTTP(context.appPort, '/nav/self-reload'),
|
||||
renderViaHTTP(context.appPort, '/nav/hash-changes'),
|
||||
renderViaHTTP(context.appPort, '/nav/shallow-routing'),
|
||||
renderViaHTTP(context.appPort, '/nav/redirect')
|
||||
renderViaHTTP(context.appPort, '/nav/redirect'),
|
||||
|
||||
renderViaHTTP(context.appPort, '/nested-cdm/index')
|
||||
])
|
||||
})
|
||||
afterAll(() => stopApp(context.server))
|
||||
|
|
Loading…
Reference in a new issue