LoginSignup
11
3

More than 3 years have passed since last update.

Nuxt で全てのページで index.html をルーティングの対象にする方法

Last updated at Posted at 2019-08-20
  1. Nuxt は vue-router をつかってルーティングしている
  2. vue-router は alias つかって対象のパスをルーティングに追加できる
  3. nuxt.config.jsextendRoutes で vue-router のルーティングを変更できる

ということをふまえて、 extendRoutes をつかって全ての route に index.html を付与した alias を追加することで実現できました。

nuxt.config.js
import { resolve } from 'path'

const nuxtConfig = {
  router: {
    extendRoutes(routes, resolve) {
      for (const route of routes) {
        route.alias = resolve(route.path, 'index.html')
      }
    }
  }
}

参考

vue-router の alias について
extendroutes について

11
3
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
11
3