Lor*_*een 5 middleware matcher next.js
I am trying to use matcher in my Next js middleware but documentation doesnt say much on how to implement the functionality.
All it shows is this without explaining which file it goes in or how to use the config in the middleware file:
export const config = {
matcher: '/about/:path*',
}
Run Code Online (Sandbox Code Playgroud)
Does anyone have a working example of how to set up the matcher for a middleware file in Next js?
Thank you.
1.与配置匹配:
\n您必须Named export从中间件文件中导出一个名为 config 的对象 ():
middleware.js || middleware.ts\nRun Code Online (Sandbox Code Playgroud)\nmiddleware.js || middleware.ts\nRun Code Online (Sandbox Code Playgroud)\r\n2.基于文件的匹配:
\n//middleware.js\n\nexport function middleware(request: NextRequest) {\n return NextResponse.redirect(new URL(\'/about-2\', request.url))\n}\n\nexport const config = {\n matcher: \'/about/:path*\',\n}Run Code Online (Sandbox Code Playgroud)\r\n| 归档时间: |
|
| 查看次数: |
16075 次 |
| 最近记录: |