mesqueeb's avatar

How to route to a custom html file in public folder?

Dear Community,

I have an SPA created outside of the Laravel framework and I built and exported the SPAindex.html so it got placed inside the Laravel public folder.

I'm trying to set this up the routing, but it's not working. This is my controller:

    public function listo()
    {
        return \File::get(public_path() . '/SPAindex.html');
    }

The files seem to get loaded when checking the network tab, but nothing is showing up... o_O

When I do valet link on the public folder and go to public.dev/SPAindex.html it shows up correctly!! But this defeats the purpose of the laravel routing I think...

Questions:

  1. How should I exactly write the controller of the route in the case I want to link public/SPAindex.html?

  2. My script that builds the SPA into the public folder is a custom webpack file for this SPA outside of Laravel. Do I still need to run Laravel mix for anything else?

0 likes
3 replies
mushood's avatar

While I dont know the answer to your specific questions, I am wondering whether you could just include the SPAindex.html into a blade file. A simple copy paste of code. And then just use normal routing.

bobbybouwmann's avatar

So you have two options here

The easiest one is creating a new .blade.php file and copy all the content in there and then simply return that view in your controller.

Another option would be putting this file directly in your /public directory and let your nginx or htaccess handle the redirect to the correct file. In this case /SPAindex.html

mesqueeb's avatar
mesqueeb
OP
Best Answer
Level 5

The answer was:

return \File::get(public_path() . '/SPAindex.html');

can work perfectly, but you CANNOT delete Laravel's index.php file inside the public folder.

  • Make sure you use a unique name for your main html file, like SPAindex.html and not use index.html
  • Make sure you keep the original laravel index.php inside the public folder.
  • If you still get a blank screen you need to: php artisan cache:clear and meta+shift+R to force a full css refresh. (this was my problem where the files would show up in network, but i'd get a blank screen)

(BTW, no need to run laravel mix for anything)

4 likes

Please or to participate in this conversation.