【发布时间】:2019-03-31 21:59:40
【问题描述】:
我正在将我的 laravel 网站更新为 vue spa,目前我在 vue 中只有 2 条路线用于测试目的。
当点击页面中的术语链接时,它可以正常工作并呈现组件。
但是当我刷新 /terms 页面应用程序抛出 404 错误。
猜猜发生了什么。
routes.js
import Home from './components/Home.vue';
import Terms from './components/Terms.vue';
export const routes = [
{
path: '/',
component: Home
},
{
path: '/terms',
component: Terms
}
];
app.js
需要('./bootstrap');
import Vue from 'vue';
import VueRouter from 'vue-router';
import Vuex from 'vuex';
import {routes} from './routes';
import StoreDate from './store';
import MainApp from './components/MailApp.vue';
Vue.use(VueRouter);
Vue.use(Vuex);
const store = new Vuex.Store(StoreDate);
const router = new VueRouter({
routes,
mode: 'history'
});
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('tasks', require('./components/Tasks.vue'));
const app = new Vue({
el: '#app',
router,
store,
components: {
MainApp
}
});
【问题讨论】:
-
这是历史模式的行为方式。它只是更改 URL 而不从 URL 请求内容。在重新加载时,它正是这样做的,并且页面不可用。见这里:stackoverflow.com/a/47617576/3233827
-
但是将模式转换为哈希确实有效,我将研究差异模式:历史/哈希
标签: vue.js laravel-5.6