forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exportPathMap
dynamic routes params fix (vercel#7846)
* Fix dynamic page export fixes vercel#7829 * Adding handling of unmatched path * Remove logs * Fix newline * Tests * Fix promise * Fix amp tests * Revert test * Adjust error document * Remove old argument * Simplify export test * Ensure page !== path for this check
- Loading branch information
Showing
8 changed files
with
107 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# The provided export path doesn't match the page. | ||
|
||
#### Why This Error Occurred | ||
|
||
An `exportPathMap` path was improperly matched to a dynamically routed page. | ||
This would result in the page missing its URL parameters. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Change your `exportPathMap` function in `next.config.js` to have a path that matches the dynamically routed page. | ||
|
||
```js | ||
module.exports = { | ||
exportPathMap: function() { | ||
return { | ||
'/': { page: '/' }, | ||
// '/blog/nextjs': { page: '/blog/[post]/comment/[id]' }, // wrong | ||
'/blog/nextjs/comment/1': { page: '/blog/[post]/comment/[id]' }, // correct | ||
} | ||
}, | ||
} | ||
``` | ||
|
||
### Useful Links | ||
|
||
- [exportPathMap](https://github.com/zeit/next.js#usage) documentation |
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
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,18 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
const Page = () => { | ||
const router = useRouter() | ||
const { post, id } = router.query | ||
|
||
return ( | ||
<> | ||
<p> | ||
{`Blog post ${post} comment ${id || '(all)'}`} | ||
</p> | ||
</> | ||
) | ||
} | ||
|
||
Page.getInitialProps = () => ({}) | ||
|
||
export default Page |
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,27 @@ | ||
/* eslint-env jest */ | ||
import { join } from 'path' | ||
import { File, runNextCommand } from 'next-test-utils' | ||
|
||
export default function (context) { | ||
describe('Dynamic routes export', () => { | ||
const nextConfig = new File(join(context.appDir, 'next.config.js')) | ||
beforeEach(() => { | ||
nextConfig.replace('/blog/nextjs/comment/test', '/bad/path') | ||
}) | ||
afterEach(() => { | ||
nextConfig.restore() | ||
}) | ||
|
||
it('Should throw error not matched route', async () => { | ||
const outdir = join(context.appDir, 'outDynamic') | ||
const { stderr } = await runNextCommand( | ||
['export', context.appDir, '--outdir', outdir], | ||
{ stderr: true } | ||
).catch(err => err) | ||
|
||
expect(stderr).toContain( | ||
'https://err.sh/zeit/next.js/export-path-mismatch' | ||
) | ||
}) | ||
}) | ||
} |
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
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