Routing issue with Laravel Nova and a VueJS SPA

profile picture

Routing issue with Laravel Nova and a VueJS SPA

As I was installing Laravel Nova into one of my new projects, which is a full VueJS Single Page Application with vue-router, I encountered a weird issue:

When I headed to the Nova admin panel, everything was empty. The layout is there but the content was not loaded.

I then opened the Chrome Dev Tools and I noticed that all requests going through the route prefix /nova-api/ responded with a 404, or with the base layout of my VueJS SPA.

MMMMHHH - Something's wrong with the routing!

In my routes/web.php file I had this:

Route::get('/{any}', 'HomeController@index')->where('any', '.*');

If you ever build a VueJS SPA with Laravel, you probably have this too into your route files.

So it seems that all /nova-api/ routes fall into this specific route.

We can fix that by updating the regex.

Here is the Solution

Route::get('/{any}', 'HomeController@index')->where('any', '^(?!nova-api).*$');

Now everything should work as expected !

Happy Coding ;)

Myd

nova
laravel
vuejs
route
spa

about me

profile picture

I consider myself as an IT Business Artisan. Or Consultant CTO. I'm a self-taught Web Developper, coach and teacher. My main work is helping and guiding digital startups.

more about me

follow me

newsletter

A weekly email with the latests articles

support my work

Start trading on binance
  • BTC

    BTC

    18SY81ejLGFuJ9KMWQu5zPrDGuR5rDiauM

  • ETH

    ETH

    0x519e0eaa9bc83018bb306880548b79fc0794cd08

  • Monero

    XMR

    895bSneY4eoZjsr2hN2CAALkUrMExHEV5Pbg8TJb6ejnMLN7js1gLAXQySqbSbfzjWHQpQhQpvFtojbkdZQZmM9qCFz7BXU

2024 © My Dynamic Production SRL All rights Reserved.