Is there any way for nuxt to render different pages according to url?

A requirement of our company is to set different subdomains for different modules. For example, the home page for renting is rent.test.com, and the home page for buying a house is sale.test.com, but for a nuxt project, the root path / can only correspond to one component, either a rental component or a purchase component. Can this situation be solved?

at first, I thought that through redirection, there is a problem, that is, if you jump to path: "/" through nuxt-link in the nuxt project, you still can"t display different pages according to the domain name.

what may come to mind at the moment is whether nuxt can dynamically render components by judging the domain name (the components here are components in the pages directory that support asyncData)


Yes, write:

in the middleware
const host = process.server
    ? context.req.headers['host']
    : window.location.host;
Menu