mpiyakhe Dhlamini
mpiyakhe Dhlamini

Reputation: 21

Angular 4 routes don't work from laravel public folder

I have a laravel json api being consumed by an angular 4 app,when it comes to deployment,I'm using forge with the contents of the dist folder in laravel's public folder,but I can't refresh any of my angular routes because laravel doesn't recognise them,they only work when navigating normally(clicking and so on) not when I enter them into the address bar of the browser or refreshing as I said.How can I solve this problem?

Upvotes: 2

Views: 1009

Answers (1)

ahadortiz
ahadortiz

Reputation: 1166

I have a same problem, so I figured out a way for over 3 hrs. Here is my way. 1. Build angular 4 project first(ng build) 2. Copy all files except for 'index.html' in dist folder to public directory of laravel project. 3. replace content of resources/views/welcome.blade.php with angular4 index.html 4. add following codes to routes/web.php

Route::get('/{any?}', function () {
    return View('welcome');
});

Please let me know if you have a problem still.

Upvotes: 6

Related Questions