Home

Issue: 1765

Need ability to set nuxt app base url based on express mountpoint

[issue link]

Is it possible to have router.base be a dynamic value, rather than hard-coded into config?

In my case, I am using express to run the nuxt app on multiple mountpoints (actually a dynamic slug mountpoint):

app.use('/:slug', slugMiddleware, nuxt.render)

So base needs to change to the value of :slug, but it appears that doing so is almost impossible.

router.base needs to be updated, as does the <base href="...">. Doing so in the nuxt app by looking at req.params.slug only works on server side, and not client.

I have tried the following with no luck:

function slugRouter(req, res) {
  // build a dynamic router
  const config = Object.assign({}, nuxtConfig)
  config.router.base = `${req.params.slug || ''}/`
  const nuxt = new Nuxt(config)
  nuxt.render(req, res)
}
app.user('/:slug', slugMiddleware, slugRouter)

And I would rather not have :slug as part of the nuxt app by ading a top /_slug directory in pages, as I need to be able to have a PWA for each individual slug, rather than the whole site.

Each slug is a unique customer.

This question is available on Nuxt.js community (#c1585)