Recently, due to some requirements of the project, we created some middleware to force all url paths within the app to lowercase, however, with dynamic paths, the links end up producing something along the lines of: /user/test?username=test, if we modify next/link to enable shallow routing, it strips the extra stuff from the url, but causes page flickers;
What would be the proper way to resolve it, rather than just doing <Link href={`/user/${username.toLowerCase()}`}>profile</Link>
middleware:
export function middleware(request: NextRequest) {
const pathname = request.nextUrl.pathname
// Check if the pathname is not lowercase
if (pathname !== pathname.toLowerCase()) {
// Create a new URL with the lowercase pathname
const url = request.nextUrl.clone()
url.pathname = pathname.toLowerCase()
// Redirect to the lowercase URL
return NextResponse.redirect(url)
}
}