Static GitHub Issues

[2204] Server Middleware, handling Aliases (404 redirection)

prev: Event listener doesn't remove when route to other page
next: Why the html tag width cannot full screen when preview on mobile

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.

<!--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/c1944">#c1944</a>)</em></sub></div>