vue 除去#符號,並部署後瀏覽器重新整理不出現404錯誤處理
阿新 • • 發佈:2018-12-31
export default new Router({
mode:"history", //把模式改成history ,就可以去除 # 符號
// base:'/',
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/firstpage',
name: 'firstpage',
component: firstpage
}
]
mode:"history", //把模式改成history ,就可以去除 # 符號
// base:'/',
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/firstpage',
name: 'firstpage',
component: firstpage
}
]
})
history模式後,部署刷新出現404錯誤問題,這個要在部署的後臺進行配置,參考https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
比如nginx下增加try_files $uri $uri/ /index.html;
location / {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
try_files $uri $uri/ /index.html;
}