1
0
Fork 0
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:
Tim Neutkens 2018-04-22 13:20:24 -07:00 committed by GitHub
parent a691dd06cf
commit 1d884efe78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 1 deletions

View file

@ -45,7 +45,7 @@ export default class App extends Component {
const {router, Component, pageProps} = this.props
const url = createUrl(router)
return <Container>
<Component url={url} {...pageProps} />
<Component {...pageProps} url={url} />
</Container>
}
}

View 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>
}
}

View 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>
}

View file

@ -40,6 +40,8 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/custom-extension'),
renderViaHTTP(context.appPort, '/styled-jsx'),
renderViaHTTP(context.appPort, '/with-cdm'),
renderViaHTTP(context.appPort, '/url-prop'),
renderViaHTTP(context.appPort, '/url-prop-override'),
renderViaHTTP(context.appPort, '/nav'),
renderViaHTTP(context.appPort, '/nav/about'),

View file

@ -119,6 +119,22 @@ export default function ({ app }, suiteName, render, fetch) {
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', () => {
it('should 404 on not existent page', async () => {
const $ = await get$('/non-existent')