【问题标题】:Laravel 5.6 & vue.js router 404Laravel 5.6 & vue.js 路由器 404
【发布时间】: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
                }
            });

按照此视频指南 https://www.youtube.com/watch?v=6FSa6XET8MY

【问题讨论】:

  • 这是历史模式的行为方式。它只是更改 URL 而不从 URL 请求内容。在重新加载时,它正是这样做的,并且页面不可用。见这里:stackoverflow.com/a/47617576/3233827
  • 但是将模式转换为哈希确实有效,我将研究差异模式:历史/哈希

标签: vue.js laravel-5.6


【解决方案1】:

您还需要在 Laravel 中添加术语路由,或者在 Laravel 网络路由中返回 404 上的 spa 视图

【讨论】:

  • 我不这么认为,据我所知,SPA 路线不能依赖于 Laravel 路线。
  • 没错,我在我的应用程序中添加了以下内容,以获取所有与我的 laravel 路线不匹配的路线:Route::get('{spa?}', function ($spa = null) { return view('app'); })->where('spa', '.*');
猜你喜欢
  • 2018-09-26
  • 2018-12-19
  • 1970-01-01
  • 2018-12-18
  • 2019-07-10
  • 2020-10-17
  • 2020-11-10
  • 2021-04-12
  • 1970-01-01
相关资源
最近更新 更多