Next.js Discord

Discord Forum

Middleware matcher problem

Unanswered
California pilchard posted this in #help-forum
Open in Discord
Avatar
California pilchardOP
Hi guys, I have a problem with my match. My actual one is :
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']

But I have this route /user/[username]
But my username can have dot int it, so if I go to : /user/loup.hello I have an 404 page because I dont know that the route corresponding to /user/[username]. TO fix that Ive try this matcher :
matcher: ["/((?!api|static|_next|favicon.ico|robots.txt)(?!.*\\/[^\\/]*\\.[^\\/]{2,4}$).*)"]

Its working that break access to some file like the /sw.js (service worker in public folder). So I dont know which matcher I have to set....

5 Replies

Avatar
California pilchardOP
Well I dont find anything about my issue, Im not the only humain to use dot in slug ahah ?
Avatar
yeah they usually use hyphen instead
Avatar
California pilchardOP
But website like Instagram, Tiktok and others, they use dot in username
Avatar
yeah, then you should update your middleware matcher and it must be a pain I believe
Avatar
California pilchardOP
I found a way and its working !
export const config = {
  matcher: [
    '/((?!api|_next|_vercel|.*\\..*).*)',
    // User pages
    '/@:username/:path*',
  ],
};

I have a rewrite for /user/[username] to /@:username so now its working adding special case in matcher