How to deploy the build of the angular 5 project in Laravel? I am deploying the build files of angular in Laravel, it is working everything fine but when I refresh after routing to any page is showing 404. The reason is it will check the controller in the backend with that URL. I tried to avoid this problem by using hash strategy but I am thinking it is not a good idea. So please help me resolve this issue.
1 Answer
As mentioned in Angular issue use following .htaccess file to load the same page of angular on refresh.
<IfModule mod_rewrite.c>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html
RewriteRule ^ index.html [L]
</IfModule>
If your index.html file is not in your root folder then you have to change the path of index.html as where your index.html exist,
like my index.html is in resources/views/ then i will write the rule in .htaccess as :
RewriteRule ^ resources/views/index.html [L]
.htaccessin root directory refer this link github.com/angular/angular/issues/19009, or If you don't want to add.htaccessfile then you have to enable your router to the HashLocationStrategy like thisRouterModule.forRoot(rootRouterConfig, { useHash: true })