mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Fix url prop override (#4191)
* Fix url prop override * Remove console.log
This commit is contained in:
parent
a691dd06cf
commit
1d884efe78
|
@ -45,7 +45,7 @@ export default class App extends Component {
|
||||||
const {router, Component, pageProps} = this.props
|
const {router, Component, pageProps} = this.props
|
||||||
const url = createUrl(router)
|
const url = createUrl(router)
|
||||||
return <Container>
|
return <Container>
|
||||||
<Component url={url} {...pageProps} />
|
<Component {...pageProps} url={url} />
|
||||||
</Container>
|
</Container>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
test/integration/basic/pages/url-prop-override.js
Normal file
16
test/integration/basic/pages/url-prop-override.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import React from 'react'
|
||||||
|
export default class extends React.Component {
|
||||||
|
static getInitialProps () {
|
||||||
|
return {
|
||||||
|
url: 'test' // This gets overridden by Next in lib/_app.js
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render () {
|
||||||
|
const {url} = this.props
|
||||||
|
return <div>
|
||||||
|
<p id='pathname'>{url.pathname}</p>
|
||||||
|
<p id='query'>{Object.keys(url.query).length}</p>
|
||||||
|
<p id='aspath'>{url.asPath}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
7
test/integration/basic/pages/url-prop.js
Normal file
7
test/integration/basic/pages/url-prop.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default ({url}) => {
|
||||||
|
return <div>
|
||||||
|
<p id='pathname'>{url.pathname}</p>
|
||||||
|
<p id='query'>{Object.keys(url.query).length}</p>
|
||||||
|
<p id='aspath'>{url.asPath}</p>
|
||||||
|
</div>
|
||||||
|
}
|
|
@ -40,6 +40,8 @@ describe('Basic Features', () => {
|
||||||
renderViaHTTP(context.appPort, '/custom-extension'),
|
renderViaHTTP(context.appPort, '/custom-extension'),
|
||||||
renderViaHTTP(context.appPort, '/styled-jsx'),
|
renderViaHTTP(context.appPort, '/styled-jsx'),
|
||||||
renderViaHTTP(context.appPort, '/with-cdm'),
|
renderViaHTTP(context.appPort, '/with-cdm'),
|
||||||
|
renderViaHTTP(context.appPort, '/url-prop'),
|
||||||
|
renderViaHTTP(context.appPort, '/url-prop-override'),
|
||||||
|
|
||||||
renderViaHTTP(context.appPort, '/nav'),
|
renderViaHTTP(context.appPort, '/nav'),
|
||||||
renderViaHTTP(context.appPort, '/nav/about'),
|
renderViaHTTP(context.appPort, '/nav/about'),
|
||||||
|
|
|
@ -119,6 +119,22 @@ export default function ({ app }, suiteName, render, fetch) {
|
||||||
expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')
|
expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('Url prop', () => {
|
||||||
|
it('should provide pathname, query and asPath', async () => {
|
||||||
|
const $ = await get$('/url-prop')
|
||||||
|
expect($('#pathname').text()).toBe('/url-prop')
|
||||||
|
expect($('#query').text()).toBe('0')
|
||||||
|
expect($('#aspath').text()).toBe('/url-prop')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should override props.url, even when getInitialProps returns url as property', async () => {
|
||||||
|
const $ = await get$('/url-prop-override')
|
||||||
|
expect($('#pathname').text()).toBe('/url-prop-override')
|
||||||
|
expect($('#query').text()).toBe('0')
|
||||||
|
expect($('#aspath').text()).toBe('/url-prop-override')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('404', () => {
|
describe('404', () => {
|
||||||
it('should 404 on not existent page', async () => {
|
it('should 404 on not existent page', async () => {
|
||||||
const $ = await get$('/non-existent')
|
const $ = await get$('/non-existent')
|
||||||
|
|
Loading…
Reference in a new issue