DEV Community

Discussion on: Handling Redirects in Nuxt.js through Middleware

kp profile image

@jackabox good writeup! glad to find another fellow dev using Laravel and Nuxt. How would you do a redirect in nuxt for:

On production: ->
On dev:
Don't redirect from homepage( to

jackabox profile image
Jack Whiting Author

Hey, sorry for the delay.

I'd look into the use of env variables here. Where you get the redirects in the middleware, we can do something like this..

const prodRedirects= require('../data/redirectsProd.json')
let redirects = require('../data/redirects.json')

if (process.env.NODE_ENV === 'production') {
  redirects = [...prodRedirects, ...redirects]

This was a pretty quick example but would probably be the way I'd go

kp profile image

@jackabox good example, thank you!