我使用vuex存储发送链接到我项目中的多个页面
我的路由器是这样的:
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/search-result',
name: 'search-result',
component: SearchResult
},
{
path: '/detail',
name: 'detail',
component: Detail
}
]
})
在我的main.js中,我这样添加:
new Vue({
created () {
let self = this
window.onbeforeunload = function (e) {
if (self.$route.path === '/detail' || self.$route.path === '/search-result') {
e = e || window.event
// old browsers
if (e) { e.returnValue = 'Changes you made may not be saved' }
// safari, chrome(chrome ignores text)
return 'Changes you made may not be saved'
} else {
return null
}
}
if (performance.navigation.type === 1) {
if (this.$route.path === '/detail' || self.$route.path === '/search-result') {
this.$router.push({ path: '/' })
} else {
console.log('reload page without redirect')
}
}
},
render: h => h(App)
}).$mount('#app')
因此,如果用户刷新,它将返回首页
在我的本地主机中,它可以工作。但是在我的服务器产品上,如果我刷新,就会出现这样的错误:
找不到404
nginx / 1.14.0(Ubuntu)
如何解决此问题?我需要对使用SPA的项目实施SSR吗?