2023-07-05 15:11:16 +02:00
---
title: 'Invalid Custom Route `source`'
---
2019-12-19 17:48:34 +01:00
2023-07-05 15:11:16 +02:00
## Why This Error Occurred
2019-12-19 17:48:34 +01:00
2023-07-05 15:11:16 +02:00
A pattern could not be parsed when defining custom routes or a middleware `matcher`.
2022-10-13 20:03:10 +02:00
2023-07-05 15:11:16 +02:00
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.
2019-12-19 17:48:34 +01:00
2023-07-05 15:11:16 +02:00
## Possible Ways to Fix It
2019-12-19 17:48:34 +01:00
Wrap the `RegExp` part of your `source` as an un-named parameter.
2023-07-05 15:11:16 +02:00
##### Custom Routes
2022-10-13 20:03:10 +02:00
2019-12-19 17:48:34 +01:00
**Before**
```js
{
source: '/feedback/(?!general)',
destination: '/feedback/general'
}
```
**After**
```js
{
source: '/feedback/((?!general).*)',
destination: '/feedback/general'
}
```
2023-07-05 15:11:16 +02:00
##### Middleware
2022-10-13 20:03:10 +02:00
**Before**
2023-07-05 15:11:16 +02:00
```ts filename="middleware.ts"
2022-10-13 20:03:10 +02:00
const config = {
matcher: '/feedback/(?!general)',
}
```
**After**
2023-07-05 15:11:16 +02:00
```ts filename="middleware.ts"
2022-10-13 20:03:10 +02:00
const config = {
matcher: '/feedback/((?!general).*)',
}
```
2023-07-05 15:11:16 +02:00
## Useful Links
2019-12-19 17:48:34 +01:00
- [path-to-regexp](https://github.com/pillarjs/path-to-regexp)
2020-07-19 06:38:20 +02:00
- [un-named parameters](https://github.com/pillarjs/path-to-regexp#unnamed-parameters)