I using laravel + vuejs
Backend use laravel (/admin)
In routes/web.php
...
Route::get('/{any?}', function () {
return view('welcome');
})->where('any', '^(?!api\/)[\/\w\.\,-]*');
When I run some url
test.com/admin
test.com/admin/users
-> All redirect to welcome layout
How to config to vue-router only run exclude /admin (backend)
Route::get('/{any?}', function () {
return view('welcome');
})->where('any', '^(?!admin).+');
It's just a regex problem, try this
Related
New to laravel so Im trying to do something that doesn't work. I'm building a backend dashboard with login & register page, these 2 pages should have different layouts. How can I do this as the way below is not working. I'm using VUE.
Of course is {any} gonna get all so is there a way to exclude pages from this?
web.php
Route::get('/{any}', function () {
return view('layouts.vue');
})->where('any', '.*');
Route::get('/login', function () {
return view('entry.vue');
})->name('login');
You should add your route on top of route with {any}.
For example:
Route::get('/somewhere', function () {
return view('somewhere');
});
Route::get('/login', function () {
return view('entry.vue');
})->name('login');
Route::get('/{any}', function () {
return view('layouts.vue');
})->where('any', '.*');
I'm building an SPA. In my web.php file I have this:
Route::get('/{any}', function () {
return view('welcome');
})->where('any', '.*');
Which is great, and I'm using Vue-Router for routing.
But I'm trying to add Stripe payments and in a lot of these videos that I've seen or articles that I've read, they often are still working with a few .blade files as well as .vue components.
I want to add a route for a blade file called checkout.blade.php
So now I will have this in web.php:
Route::get('/{any}', function () {
return view('welcome');
})->where('any', '.*');
Route::view('/checkout-now', 'checkout');
The issue is I don't see anything, just a blank white page when I go to this route, I assume it has to do with the first Route, but how do I get around this? How can I see .blade routes in my SPA?
In this case I recommend to keep all your routes before the any route.
Route::view('/checkout-now', 'checkout');
.
.
Route::get('/{any}', function () {
return view('welcome');
})->where('any', '.*'); // Must be at the end
if you just need few route for vue router
$paths = ['vue-path', 'vue-path-id'];
foreach ($paths as $path) {
Route::get($path, function () {
return view('welcome');
});
}
Route::view('/checkout-now', 'checkout');
The question is pretty simple.
in order to build a Simple Page Application (SPA) with Laravel and VueJS , should all the paths present in router.js ( the file defining paths for SPA) be also present in web.php of Laravel ?
For example I am using the source code from here :
router.js inside resources/assets/js/frontend has :
export default [
{ path: '/create', component: SubmitTicketFormComponent },
{ path: '/view/:ticketId', name: 'client-view-ticket', component: ViewTicketComponent, props: true }
];
But the web.php inside routes folder has
Route::get('/', function () {
return view('welcome');
});
Route::get('/admin', function () {
return view('admin');
});
Route::post('/login', 'Auth\LoginController#login');
Route::post('/logout', 'Auth\LoginController#logout')->name('logout');
//Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
And the api.php inside routes folder has :
Route::middleware('auth:api')->group(function() {
Route::get('/profile', 'ProfileController#index');
Route::apiResource('/admin/tickets', 'Admin\TicketsController');
});
Route::apiResource('tickets', 'TicketsController');
So what are the rules regarding the path or route declaration for both VueJs and Laravel ?
If you want to have a SPA and keep some of the Laravel pages you need to have a route like this:
Route::get('/{any}', 'VueController#index')->where('any', '.*');
This can be at the end of your routing file, so if it does not match the existing Laravel routes and it will open the Vue SPA and the routing will be handled from there.
Just trying out laravel 5.5 which I installed in cpanel. Only the root route is working:
Route::get('/', function () {
return view('public/content/home-content');
});
Even this isn't working
Route::get('/about', function () {
return view('public/content/about-content');
});
It also work:
www.mydomain/index.php/about
How can I solve this error
I just need to know how i can set the login page as default page of my site.
Route::get('/', function () {
return view('welcome');
});
I need something like this:
Route::get('/', function () {
return view('auth.login');
});
It's possible?
Thanks
Yes, it's possible, just put this route before all other routes and this will work.
If you're using standard Laravel 5.2 auth system, you can create this route and use it before all other routes:
Route::get('/', 'Auth\AuthController#getLogin');