Files
vercel__next.js/errors/invalid-route-source.mdx
Jiwon Choi bc59f210b0 docs: Deprecation of Middleware (#84710)
This PR removes middleware docs and adds a "Migration to Proxy" section
to the Proxy docs, which explains the rationale for the renaming to
Proxy and provides a migration guide.

Did not remove `middleware-upgrade-docs` as it's an upgrade doc from the
legacy middleware.

Below are untouched as they need codebase changes:

- `instrumentation` docs - `onRequestError` has `context.routeType` as
`'middleware'`
- `adapterPath` docs - has `MiddlewareMatcher` type example
- `ProxyConfig` - has a user-facing `MiddlewareMatcher` type

---------

Co-authored-by: Joseph Chamochumbi <joseph.chamochumbi@vercel.com>
2025-10-17 20:03:13 +02:00

57 lines
1.0 KiB
Plaintext

---
title: 'Invalid Custom Route `source`'
---
## Why This Error Occurred
A pattern could not be parsed when defining custom routes or a proxy `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'
}
```
### Proxy
**Before**
```ts filename="proxy.ts"
const config = {
matcher: '/feedback/(?!general)',
}
```
**After**
```ts filename="proxy.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)