未验证 提交 1d884efe 编写于 作者: T Tim Neutkens 提交者: GitHub

Fix url prop override (#4191)

* Fix url prop override

* Remove console.log
上级 a691dd06
......@@ -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>
}
}
......
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>
}
}
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, '/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'),
......
......@@ -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')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册