Static GitHub Issues

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

prev: Bug: Nuxt broke Enter transition
next: Vue2-google-maps build error

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.

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1585">#c1585</a>)</em></sub></div>