鍍金池/ 問(wèn)答/HTML/ vue router history的組件加載問(wèn)題

vue router history的組件加載問(wèn)題

在使用原本的hash模式里切換頁(yè)面也不需要重新加載的。但是現(xiàn)在切換到history模式后,點(diǎn)擊加載其他頁(yè)面就要重新加載全部?jī)?nèi)容。
要怎么才能像原來(lái)那樣按需加載,不用全部重新加載

nginx

  location / {
    alias /web/XXX/web/dist/;
    try_files $uri $uri/ /index.html;
  }

Vue-Router

export default new Router({
    mode: 'history',
    history: true,
    routes: [
        {
            path: '/',
            name: 'index',
            component: (resolve) => {
                require(['./pages/index'], resolve)
            }
        }
        {
            path: '/note',
            name: 'note',
            component: (resolve) => {
                require(['./pages/note/index'], resolve)
            }
        }
        
    ]
})
回答
編輯回答
筱饞貓

history模式下所有不走router機(jī)制的跳轉(zhuǎn)都會(huì)重新請(qǐng)求所有內(nèi)容,整不了的,所以得走router機(jī)制。

2017年1月22日 04:31
編輯回答
傲嬌范

把鏈接里的

<a href='/note'></a>

換成

<router-link to='/note'></router-link>

就行了。。我去

2017年10月11日 14:50