mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Handle pages with no default export and show an error. (#1484)
That error is meaningful and easy to find the issue.
This commit is contained in:
parent
bc2d5f3bdb
commit
97c472c0c8
|
@ -19,6 +19,11 @@ export default class App extends Component {
|
|||
render () {
|
||||
const { Component, props, hash, err, router } = this.props
|
||||
const url = createUrl(router)
|
||||
// If there no component exported we can't proceed.
|
||||
// We'll tackle that here.
|
||||
if (typeof Component !== 'function') {
|
||||
throw new Error(`The default export is not a React Component in page: "${url.pathname}"`)
|
||||
}
|
||||
const containerProps = { Component, props, hash, router, url }
|
||||
|
||||
return <div>
|
||||
|
|
1
test/integration/basic/pages/no-default-export.js
Normal file
1
test/integration/basic/pages/no-default-export.js
Normal file
|
@ -0,0 +1 @@
|
|||
export default {}
|
|
@ -58,6 +58,12 @@ export default function ({ app }, suiteName, render) {
|
|||
expect(html.includes('Zeit')).toBeTruthy()
|
||||
})
|
||||
|
||||
test('default export is not a React Component', async () => {
|
||||
const $ = await get$('/no-default-export')
|
||||
const pre = $('pre')
|
||||
expect(pre.text()).toMatch(/The default export is not a React Component/)
|
||||
})
|
||||
|
||||
test('error', async () => {
|
||||
const $ = await get$('/error')
|
||||
expect($('pre').text()).toMatch(/This is an expected error/)
|
||||
|
|
Loading…
Reference in a new issue