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.
Add err.sh for invalid multi-match usage (vercel#9498)
* Adds err.sh for multi-match error * Fix missing apostrophe * Update regex to catch other param names * Add test for multi-match error * Update test/integration/invalid-multi-match/test/index.test.js
- Loading branch information
1 parent
874d3fd
commit ff2d28c
Showing
5 changed files
with
125 additions
and
1 deletion.
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,27 @@ | ||
# Invalid Multi-match | ||
|
||
#### Why This Error Occurred | ||
|
||
In one of your custom-routes you specified a multi-match `/:path*` and used it in your `destination` without adding the `*` in your `destination` e.g. `destination: '/another/:path'` | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Add `*` to your usage of the multi-match param in your `destination`. | ||
|
||
**Before** | ||
|
||
```js | ||
{ | ||
source: '/:path*', | ||
destination: '/another/:path' | ||
} | ||
``` | ||
|
||
**After** | ||
|
||
```js | ||
{ | ||
source: '/:path*', | ||
destination: '/another/:path*' | ||
} | ||
``` |
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,12 @@ | ||
module.exports = { | ||
experimental: { | ||
rewrites() { | ||
return [ | ||
{ | ||
source: '/:hello*', | ||
destination: '/:hello', | ||
}, | ||
] | ||
}, | ||
}, | ||
} |
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,15 @@ | ||
import { useRouter } from 'next/router' | ||
|
||
console.log('hello from hello.js') | ||
|
||
const Page = () => { | ||
const { query } = useRouter() | ||
return ( | ||
<> | ||
<h3>hello world</h3> | ||
<span>{JSON.stringify(query)}</span> | ||
</> | ||
) | ||
} | ||
|
||
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,57 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import { join } from 'path' | ||
import { | ||
launchApp, | ||
killApp, | ||
findPort, | ||
nextBuild, | ||
nextStart, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
let appDir = join(__dirname, '..') | ||
let stderr = '' | ||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should show error for invalid mulit-match', async () => { | ||
await renderViaHTTP(appPort, '/hello') | ||
expect(stderr).toContain( | ||
'To use a multi-match in the destination you must add' | ||
) | ||
expect(stderr).toContain('https://err.sh/zeit/next.js/invalid-multi-match') | ||
}) | ||
} | ||
|
||
describe('Custom routes', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort, { | ||
onStderr: msg => { | ||
stderr += msg | ||
}, | ||
}) | ||
}) | ||
afterAll(() => killApp(app)) | ||
runTests(true) | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort, { | ||
onStderr: msg => { | ||
stderr += msg | ||
}, | ||
}) | ||
}) | ||
afterAll(() => killApp(app)) | ||
runTests() | ||
}) | ||
}) |