Adriano
Adriano

Reputation: 3934

nuxt & vue - javascript redirect when working on a generated static website

I'm working on a static website generated by nuxt&vue.
I would like to create a redirect for a page I'm no longer using.

So, the code I would like to run is:
window.location.replace("[new_url]")

How do I make sure this javascript code is ran as soon as the user visits the page?

Upvotes: 0

Views: 1283

Answers (1)

Nicolas Pennec
Nicolas Pennec

Reputation: 7631

You can use the redirect helper from Nuxt to redirect the user to another route: https://nuxtjs.org/docs/2.x/internals-glossary/context#redirect

Example to redirect from /old to /new page:

// page/old.vue

<script>
export default {
  asyncData({ redirect }) {
    return redirect('/new')
  }
}
</script>

Upvotes: 2

Related Questions