nuxt-community / redirect-module

No more cumbersome redirects for Nuxt 2!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Large Number of Redirects

lanbau opened this issue · comments

Hi what is the best way to implement large number of redirects?

My setup works well but my nuxt.config.js is pretty lengthy.

I have 150 product links, does it mean my array in nuxt.config.js is 150 lines long?

Nuxt.config.js

const productRedirects = '[{"from":"/products/all-over-hair-body-shampoo","to":"/all-over-hair-body-shampoo","statusCode":301}]';

module.exports = {
  ...
  ...
  redirects: JSON.parse( productRedirects )
}

Hey! 👋

you could either extract the array to a separate JS file or (if possible) use regex to parse redirects if they all follow a pattern 👍

Thanks for the advice @manniL . Extracting the array to a separate JS file works!

external.js

module.exports = [1, 2, 3]

app.js

const array = require('./external.js')

Question on where best to put that JSON file, does it need to be in a place that gets included in the build files? I'm guessing it only needs to be on the server? Like I have a JSON file of redirects that is 700kb, I'd rather not have it added to my client side code if possible.