Home

Issue: 2204

Server Middleware, handling Aliases (404 redirection)

[issue link]

Hi,
for some reasons I have to handle my vue-router aliases and some times return a 404 if some given conditions are not respected.
I see I can easily set res status to 404 like below:

module.exports = function (req, res, next) {
  // check incoming request and do some logic
  // ......................
  // then check if the condition is true and eventually redirect to 404
  if (aliasesLookup[req.path] && aliasesLookup[req.path] !== country) {
    res.status(404).send('Not found')
    return
  }
  next()
}

However, I would like also to set the nuxt.js 404 template, is there any way to achieve that? At the moment I just get a white page with the 404 error in console.

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