Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for catch-all routes with SSG (#10175)
* Add support for catchall routes with SSG * Add test for invalid catchall param in getStaticPaths
- Loading branch information
Showing
6 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/integration/prerender-invalid-catchall-params/pages/[...slug].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
|
||
// eslint-disable-next-line camelcase | ||
export async function unstable_getStaticPaths() { | ||
return [{ params: { slug: 'hello' } }] | ||
} | ||
|
||
// eslint-disable-next-line camelcase | ||
export async function unstable_getStaticProps({ params }) { | ||
return { | ||
props: { | ||
post: params.post, | ||
time: (await import('perf_hooks')).performance.now(), | ||
}, | ||
} | ||
} | ||
|
||
export default () => { | ||
return <div /> | ||
} |
17 changes: 17 additions & 0 deletions
17
test/integration/prerender-invalid-catchall-params/test/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { nextBuild } from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
const appDir = join(__dirname, '..') | ||
|
||
describe('Invalid Prerender Catchall Params', () => { | ||
it('should fail the build', async () => { | ||
const out = await nextBuild(appDir, [], { stderr: true }) | ||
expect(out.stderr).toMatch(`Build error occurred`) | ||
expect(out.stderr).toMatch( | ||
'A required parameter (slug) was not provided as an array' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export async function unstable_getStaticProps({ params: { slug } }) { | ||
return { | ||
props: { | ||
slug, | ||
}, | ||
revalidate: 1, | ||
} | ||
} | ||
|
||
export async function unstable_getStaticPaths() { | ||
return [ | ||
{ params: { slug: ['first'] } }, | ||
'/catchall/second', | ||
{ params: { slug: ['another', 'value'] } }, | ||
'/catchall/hello/another', | ||
] | ||
} | ||
|
||
export default ({ slug }) => <p id="catchall">Hi {slug.join('/')}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters