我已经成功地设置了vue-router,但我在将它与我的laravel 5.3路由混合时遇到了一些问题。
我有一个回家的php路由:
Route::get('/', array('as' => 'home', 'uses' => 'HomeController@showWelcome'));并且我已经设置了vue-router路由:
'/user-feed': {
name: 'user-feed',
title: 'User Feed',
component: Feed
},
'*': {
component: PageNotFound
}在我的web.php路由文件中,我有以下内容:
Route::get('/', array('as' => 'home', 'uses' => 'HomeController@showWelcome'));
// use vue-router route
Route::get('/{subs}', [function () {
return view('layouts');
}])->where(['subs' => '.*']);我这里的问题是,当我更改路由的顺序(在家庭路由器之前使用vue路由器)并尝试访问home路由时,将呈现Page not found vue- route,并且可以通过v-link使用user-feed。
当vue路由器在home路由之后时,主页被正确地呈现,但是vue-router不能通过v-link访问,并且我可以访问vue路由器的唯一方法是手动输入url。
如何与我的laravel route一起使用vue-router
发布于 2016-09-27 09:28:19
除非您有合理的理由,否则您真的不应该将两者一起用于前端导航。 Vue 路由器适用于单页应用程序,而 Laravel 的路由系统适用于多页应用程序或 API。我认为最常见的设置是让所有 Laravel 路由,除了说/api/ 重定向到包含你的 SPA 的单个模板,比如app.blade.php。从那里您的 vue-router 将成为您的前端导航,您的/api/端点将成为您将数据输入和输出 laravel 的方式。
发布于 2016-09-27 13:03:11
试试这个,这可能会解决你的问题
export var router = new Router({
hashbang: false,
history: true,
linkActiveClass: 'active',
mode: 'html5'
});
router.map({
'/': {
name: 'home',
component: Home
},
'/dashboard': {
name: 'dashboard',
component: Dashboard
},
'/404notfound': {
name: 'pagenotfound',
component: Pagenotfound
}
});
// For every new route scroll to the top of the page
router.beforeEach(function() {
window.scrollTo(0, 0);
});
// If no route is matched redirect home
router.redirect({
'*': '/404notfound'
});https://stackoverflow.com/questions/39713481
复制相似问题