Next.js Discord

Discord Forum

next/link Behavior with CDN

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I’m working on a web app that we’re incrementally moving over to the Next.js App Router

We are self hosting the app using Node and once we deploy we will be routing requests to the correct origin using our CDN

Will next/link work seamlessly if the href is relative, but the old web app will be handling the request? Our old origin will be responding to the GET request with HTML and it looks like it will work, but I figured I’d double check.

Thanks!

1 Reply

Vizsla
Are you setting the custom CDN with the assetPrefix config? https://nextjs.org/docs/app/api-reference/next-config-js/assetPrefix

If so, I'm not sure if relative next/link href's will work if the route isn't defined in your new app router NextJS project. You might have to set up custom rewrites either with some pattern matching that works for your setup, or for specific paths: https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites#header-cookie-and-query-matching

That way you can match /old/path relative next/link to my.newcdn.com/old/path if I understand your setup correctly