next.js
f5198b48 - [metadata] fix the metadata route like pages and refactor utils (#77264)

Commit
280 days ago
[metadata] fix the metadata route like pages and refactor utils (#77264) ### What - Fix the metadata route like pages rendering, e.g. `/sitemap/page.js` should still work properly rather than being treated as route - Refactor metadata utils, should prefer using the file matcher rather than just checking the route or page path if possible to determine if it's metadata route Previously the metadata regex didn't handle the route well. For example: When it's not checking the end, `/opengraph-image-abc` can still be matched, but actually it's not a valid metadata route. This PR refines the route/file path regex matching for metadata entries and add more tests. The underlayer helper - `isMetadataRouteFile`, you can use it to check if a file path is an metadata entry. The helpers built on top of it: - `isMetadataPage`: determine if a page path is metadata route, the input is more like a pathname. - `isMetadataRoute`: determine if a route is metadata route, the input contains nextjs route suffix like `/route`. We change the most of places to use `isMetadataRouteFile` if possible, since it's more accurate, especially when we check the static metadata routes, e.g. `/opengraph-image.png`, `/opengraph-image.js` will require the extension check and strict matching on file name convention. Closes #77250 Fixes #76747
Author
Parents
Loading