Next.js Discord

Discord Forum

middleware matcher to ignore public folder

Answered
Cape lion posted this in #help-forum
Open in Discord
Avatar
Cape lionOP
export const config = { matcher: [ '/((?!api|_next).*)' ]};

I'm working on implementing i18n in my project, and want to prevent the middleware from triggering on /*.svg and /*.png. How can I add this to the middleware matcher?
Answered by B33fb0n3
@Cape lion you can do this by adding a if-phrase into your middleware. It could look like this:
if (['/manifest.json', '/icon.png', ...].includes(pathname) || pathname.startsWith("/yourfolder"))
        return;


Of you can change the startsWith part with endsWith to check the end of your requested files
View full answer

2 Replies

Avatar
B33fb0n3
@Cape lion you can do this by adding a if-phrase into your middleware. It could look like this:
if (['/manifest.json', '/icon.png', ...].includes(pathname) || pathname.startsWith("/yourfolder"))
        return;


Of you can change the startsWith part with endsWith to check the end of your requested files
Answer
Avatar
Cape lionOP
Thanks