DEV Community

Gündoğdu Yakıcı
Gündoğdu Yakıcı

Posted on

What's the matcher?

Hi there,

I'm new in Next.js 13. I have a question for you. I will make a multi language web site and for this I use middleware.js.
My folder structure; app/[lang]/file-name.jsx etc.

But I don't understand what's meaning the matcher feature. What does it do? What happens if I don't use it?

export const config = {
matcher: ["/((?!_next).*)", "/:lang*"],
};

I already have access to the incoming parameter because of the [lang] structure. Why do we use it for matcher. What is the logic to use here? Can you explain with an example?

Top comments (3)

Collapse
 
simplycomplexable profile image
Zack Sunderland

I'm not sure where you're finding that config object in documentation, but you're right you don't need it at all.

Collapse
 
gundogduyakici profile image
Gündoğdu Yakıcı
Collapse
 
simplycomplexable profile image
Zack Sunderland

I missed that you're using middleware. You don't actually need middleware to support different locales as long as you're not doing anything crazy with the url. What you've described is the default behavior.
If you do need to use middleware, the matcher is a regex that lets next know which routes the middleware should run on. For example you don't need to intercept compiled files so the regex you shared is excluding any paths that start with _next, where all the compiled files live.