rsnext/errors/invalid-route-source.mdx
Delba de Oliveira 44d1a1cb15
docs: Migrate error messages to MDX and App Router. (#52038)
This PR is part of a larger effort to migrate error messages to MDX and
use App Router: https://github.com/vercel/front/pull/23459
2023-07-05 06:11:16 -07:00

56 lines
1 KiB
Text

---
title: 'Invalid Custom Route `source`'
---
## Why This Error Occurred
A pattern could not be parsed when defining custom routes or a middleware `matcher`.
This could have been due to trying to use normal `RegExp` syntax like negative lookaheads (`?!exclude`) without following [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp)'s syntax.
## Possible Ways to Fix It
Wrap the `RegExp` part of your `source` as an un-named parameter.
##### Custom Routes
**Before**
```js
{
source: '/feedback/(?!general)',
destination: '/feedback/general'
}
```
**After**
```js
{
source: '/feedback/((?!general).*)',
destination: '/feedback/general'
}
```
##### Middleware
**Before**
```ts filename="middleware.ts"
const config = {
matcher: '/feedback/(?!general)',
}
```
**After**
```ts filename="middleware.ts"
const config = {
matcher: '/feedback/((?!general).*)',
}
```
## Useful Links
- [path-to-regexp](https://github.com/pillarjs/path-to-regexp)
- [un-named parameters](https://github.com/pillarjs/path-to-regexp#unnamed-parameters)