1

I've set the document root of my apache virtual host config file to laravel's public directory. I have an angular 4 app that builds into the public/dashboard-dist directory. I have added this directory as a location to search for views config/view.php like this:

'paths' => [
    resource_path('views'),
    public_path('dashboard-dist'),
],

And I can redirect the user to the dashboard-index.php in this directory after a successful login. But all asset links in this file (js,css etc.) fail to load and return 404. For example bootstrap.min.css hails from:

http://localhost/assets/css/bootstrap.min.css (404)

When I change the href attribute of this file as:

<link href="/dashboard-dist/assets/css/bootstrap.min.css" rel="stylesheet" />

I get a 200 and the file gets loaded. But I don't want to change all URLs in this angular 4 app and instead have a single server configuration to set subdirectory document root to itself. I'd prefer to use .htaccess in public directory to do this so when I upload the site to real server it will work out of the box. How can I achieve this?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
moonwalker
  • 1,157
  • 1
  • 18
  • 34

1 Answers1

0

The best solution to this type of problem is to run:

ng build --base-href /dashboard-dist/ 

to build the angular app. This will add

<base href="/dashboard-dist/">

to the build's dashboard-index.php and all asset links will work from now on.

moonwalker
  • 1,157
  • 1
  • 18
  • 34