Vue 路由不起作用.Laravel 8 + Vue [英] Vue Route does not working. Laravel 8 + Vue
本文介绍了Vue 路由不起作用.Laravel 8 + Vue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道我的代码有什么问题,或者它在 laravel 8 上有什么问题?
I don't know what's wrong with my code or it issues on laravel 8?
路由器JS文件
import Vue from 'vue'
import VueRouter from 'vue-router'
import FirstPage from './components/pages/FirstPage.vue'
Vue.use(VueRouter)
const routes = [
{ path: '/new-route', component: FirstPage }
]
export default new VueRouter({
mode: 'history',
routes
})
应用 JS 文件
require('./bootstrap');
window.Vue = require('vue')
import router from './router'
Vue.component('mainapp', require('./components/mainapp.vue').default)
const app = new Vue ({
el: '#app',
router
})
网页 PHP 文件
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TestController;
Route::get('/', function () {
return view('welcome');
});
Route::get('test', [TestController::class, 'test']);
Route::any('{slug}', function(){
return view ('error');
});
有什么想法吗?或任何建议.(需要发布更多详细信息)
does any have an idea? or any suggestions. (It requires more details to be posted)
推荐答案
你需要在web.php
Route::any('{all}', [TestController::class, 'test'])
->where('all', '^(?!api).*$')
->where('all', '^(?!storage).*$');
或
Route::any('{all}',function(){
return view('main'); // it should be main blade file
})
->where('all', '^(?!api).*$')
->where('all', '^(?!storage).*$');
无需#
此代码不包括 api
和 storage
url,因此它们都可以工作,其他所有路由都可以捕获,因此 vuejs 发挥了它的魔力
this code exclude api
and storage
url so both will work and other all route catch so vuejs do its magic
这篇关于Vue 路由不起作用.Laravel 8 + Vue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文