1
0
Fork 0
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:
Arunoda Susiripala 2017-05-18 10:54:57 +05:30 committed by GitHub
parent a8fdbb261e
commit 92b0a690be
4 changed files with 18 additions and 1 deletions

View file

@ -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 = {}

View file

@ -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' } },

View file

@ -0,0 +1,11 @@
const Page = ({ query }) => (
<div>
{ `Query is: ${query}` }
</div>
)
Page.getInitialProps = ({ query }) => {
return { query: JSON.stringify(query) }
}
export default Page

View file

@ -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: {}/)
})
})
}