2017-06-15 58 views
0

我正在使用Laravel 5.4,VueJS,AXIOS,VueRouter的应用程序。 VueRouter负责所有应用程序的导航,除以下航线配置:移动到下一个路线,如果找不到一些URL

<?php 

/* 
|-------------------------------------------------------------------------- 
| Web Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register web routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| contains the "web" middleware group. Now create something great! 
| 
*/ 

Auth::routes(); 


Route::get('/{catchall?}', ['as' => 'start', 'middleware' => 'auth', function() { 
    return view('home')->with([...]); 
}])->where('catchall', '.*'); 

这基本上将用户重定向到“基地”刀片文件,其中包含了<router-link></routerlink>。然而,我现在在我的应用程序中实现了一个任何人都可以访问的页面(不需要auth中间件),并且完全利用了不同的布局(因此需要一个新的刀片文件)。

优选地,这将这样获得:

app.sample.com/{some-string}

而不是别的这样的:

app.sample.com/survey/{some-string}

{some-string}是随机生成的字符串,然后扔进D B。可以通过我的一个模型访问。据我了解,我可以做这样的事情:

Route::get('/{some-string}', '[email protected]')

配售这个包罗万象应该工作上面。但是,如果/{some-string}与数据库中的任何内容不匹配,我宁愿将它处理为catchall,它将服务于home.blade.php

是否有任何干净的方式来处理此问题?

回答

0

你基本上描述了RedirectIfAuthenticated中间件,至少这是我将如何处理这个问题。利用中间件来检查用户的身份验证级别,并在将它们提供给应用程序之前执行任何路由匹配。

+0

这是一个很好的观点 - 甚至没有想过要以这种方式解决问题。我感觉合理! – mdobrenko