I want to build and deploy angular 10 with laravel backend to the server, in which folder I should upload the angular and which folder should I upload the laravel?
1 Replies
1. You should rewrite the welcome.blade.php
view in the resource/view
directory to be like your index.html
angular file from the dist folder.
2. in the public
folder you also need file .htaccess
, where you should place this code:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
this is required for your API calls from an angular
app in order to be processed by laravel
routing (without this .htaccess
file in response to all my angular API calls I got 404 - Object not found)
3. And finally you need to have one more .htaccess
file in your root directory with the content described in the article above.
After these settings, all should work as expected.
And one more thing, maybe not so important as described above. In order to prevent angular and laravel routing conflicts in the angular app, I set the HashLocationStratagy
provider in order to get /#/ in angular routes.