make middleware.ts matcher work on all routes
Answered
Polar bear posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Polar bearOP
export const config = {
matcher: ["/", "/dashboard"],
};
Hey guys, the above is my current middleware.ts matcher code.
Is it possible to change this in order for it to work on all routes by default?
Removing that code snippet from the middleware.ts or doing something like
"/(.*)"
results in the browser logs to say what's in the picture (I am using app router with src/
directory):![Image](https://cdn.discordapp.com/attachments/1266394096512139394/1266394096709144658/image.png?ex=66a4fce9&is=66a3ab69&hm=39a0b6293a2e4fa376a35c3c9fe42d0b54255c4f822ace5a17eac003815a8f24&)
Answered by B33fb0n3
oh, you can change this example as well:
export const config = {
matcher: [
/*
*
Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
*/
'/((?!api|_next/static).*)',
],
}
7 Replies
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
you can do something like this:
export const config = {
matcher: [
/*
*
Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
}
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Polar bearOP
but that results in my favicon and images to not being loaded anymore
I tried that
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
oh, you can change this example as well:
export const config = {
matcher: [
/*
*
Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
*/
'/((?!api|_next/static).*)',
],
}
Answer
![Avatar](https://cdn.discordapp.com/avatars/301376057326567425/788b75eb8862277af3d31d317ada783f.webp?size=256)
B33fb0n3
@Polar bear solved?
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Polar bearOP
solved tyvm
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/44415017de6fed2ccd5d44b4b2051ac0.webp?size=256)
joulev
(by the way if you want to run middleware in truly every route, simply remove the matcher)