Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

christopher's avatar

Vue Router in Laravel - Cant go directly to a URL

I am using Laravel 5.3 with Vue 2 & Vue- Router.

My Problem is if i enable the history mode i cant access the routes directly. So simple: The history mode removes the /#/ from the URL. Therefore if you access for example domain.dev/test is not going to work since Laravel is throwing an NotFoundHttpException Error. Which makes sense of course, because this route doesnt exist in my routes file, since i am using the Vue-Router.

If i come from the Root Site e.g domain.dev and click then on test this is working. But not if i directly enter the full URL e.g domain.dev/test since this is calling a laravel route which doesnt exist.

I hope you understand what i am talking about :)

Is there any way to solve this problem?

I could use the complete Vue Project outside of Laravel, but i want to have it all in my resources/js directory. is there any other Solution?

0 likes
9 replies
guc43's avatar
guc43
Best Answer
Level 2

You can put this at the end of your routesfile. This worked for me. Found this solution in a repo from Matt Stauffer.

Route::get('/{vue_capture?}', function () {
    return view('pages.home');
})->where('vue_capture', '[\/\w\.-]*');
12 likes
shakee93's avatar

what if i want to exclude a specific url from vue ? i know we can specify that route above the vue route. but the route is actually generated from a package. what am i supposed to do ?

Firemaps's avatar

That answer is a great quick fix. Would love an explanation about how it works and how it can be customized for other urls

jaripp's avatar

This vue_capture route is working nicely, but what about route parameters?

const routes = [
    { path: '/user/:id', component: User }
]

This just gives error Uncaught SyntaxError: Unexpected token <

Majid7's avatar

Thank you, @guc43

In Lumen you should just add "Route::get('/{vue_capture:[/\w.-]*}', function () { return view('pages.home'); });" to web.php route file.

Please or to participate in this conversation.