When working with internationalization (i18n) in Next.js 13 within the app directory, there is an issue where assets in the public folder directory cannot be accessed.
To resolve this issue, follow these steps:
- Define a regular expression pattern to match all file extensions:
const PUBLIC_FILE = /\.(.*)$/
- Modify your middleware function to include a check for public files using the PUBLIC_FILE pattern. If a match is found, skip further processing:
if (PUBLIC_FILE.test(req.nextUrl.pathname)) return
By implementing these changes, you will be able to access assets in the public folder directory when working with Next.js 13 and i18n.
Special thanks to the Stack Overflow user who provided this solution: Answer Link