18
9

More than 5 years have passed since last update.

Nuxtでredirectする方法

Posted at

https://github.com/nuxt/nuxt.js/issues/1843 によると、設定ベースでやる方法はない。

  • A. 空のページを配置して、fetchでprogrammaticallyにrecirectさせる
  • B. middlewareで似たようなことする

A. 空のページを配置して、fetchでprogrammaticallyにrecirectさせる

例: /にアクセスすると/postsにリダイレクトさせたい場合

  • pages/
    • index.vue
    • posts/
      • index.vue
pages/index.vue
<script lang="ts">
import Vue from 'Vue'
export default Vue.extend({
  fetch({ redirect }) {
    redirect(301, '/posts')
  }
})
</script>

(vue-class-component上ではどう書くのかわからなかった)

B. middlewareで似たようなことする

18
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
9