Next.js Discord

Discord Forum

How can I rewrite routes from one Next.js app to another Next.js app using next.config.js?

Unanswered
Tonkinese posted this in #help-forum
Open in Discord
TonkineseOP
So the thing is I have done some changes but the assests like font, images css etc for destinations are getting fetched from source domain and hence causing issue where it's not able to fetch and giving 404. Has anyone done something similar. can someone help how can I fix it? Also I am using npm run. start and not vercel to host these two websites.
{
source: "/:countryCode",
destination: "https://some-domain/",
basePath: false,
},
{
source: "/:countryCode/brand",
destination: "https://some-domain//brand", // Matched parameters can be used in the destination
}

7 Replies

@Tonkinese
not much following your problem
so your problem is not being able to fetch those assets?
or you want to setup configuration for redirection?
TonkineseOP
Hey @James4u
I have two applications, both built with Next.js—let’s call them App1 and App2. I’m using rewrites in App1 to route certain pages (like / and /brand) to corresponding pages in App2. The issue arises when App2’s pages load: they fail to fetch assets like .css, .js, .tff, and images because App1 is looking for them in its own _next/ folder, rather than fetching them from App2’s _next/ folder. This causes the assets to be missing, breaking the styles and functionality of the pages from App2.
Hmm then what about uploading all the assets to the CDN and use them?
You will probably lose all built-in optimizations like images, fonts ...