mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Add a default value of '{}' to query in the export mode. (#2003)
This commit is contained in:
parent
a8fdbb261e
commit
92b0a690be
|
@ -88,7 +88,7 @@ export default async function (dir, options) {
|
|||
for (const path of exportPaths) {
|
||||
log(` exporting path: ${path}`)
|
||||
|
||||
const { page, query } = exportPathMap[path]
|
||||
const { page, query = {} } = exportPathMap[path]
|
||||
const req = { url: path }
|
||||
const res = {}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ module.exports = {
|
|||
return {
|
||||
'/': { page: '/' },
|
||||
'/about': { page: '/about' },
|
||||
'/get-initial-props-with-no-query': { page: '/get-initial-props-with-no-query' },
|
||||
'/counter': { page: '/counter' },
|
||||
'/dynamic-imports': { page: '/dynamic-imports' },
|
||||
'/dynamic': { page: '/dynamic', query: { text: 'cool dynamic text' } },
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
const Page = ({ query }) => (
|
||||
<div>
|
||||
{ `Query is: ${query}` }
|
||||
</div>
|
||||
)
|
||||
|
||||
Page.getInitialProps = ({ query }) => {
|
||||
return { query: JSON.stringify(query) }
|
||||
}
|
||||
|
||||
export default Page
|
|
@ -22,5 +22,10 @@ export default function (context) {
|
|||
const html = await renderViaHTTP(context.port, '/dynamic-imports')
|
||||
expect(html).toMatch(/Welcome to dynamic imports./)
|
||||
})
|
||||
|
||||
it('should give empty object for query if there is no query', async() => {
|
||||
const html = await renderViaHTTP(context.port, '/get-initial-props-with-no-query')
|
||||
expect(html).toMatch(/Query is: {}/)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue