Search code examples
ionic-frameworkserve

ionic 4 sub paths not loading when running ionic serve


I had an ionic 4 beta project of --type=angular that was loading at any path without issue.

Periodically, i have been updating my packages by running an npm update and am currently at:

"@ionic/angular": "^4.0.2"

as well as updated installs for the ionic cli, and am currently at:

CLI 4.10.3

I am not sure when this app loading issue started, but i suspect it was after running the last npm update or update install of the cli.

When running ionic serve my application loads correctly, and i am able to navigate to all sub paths without any issues.

However, when:

• refreshing the browser while viewing a sub path

• attempting to enter a url with a sub path

• live reloading while viewing a sub path

the app attempts to load all js files relative to the sub path and fails to run like so:

http://localhost:8100/page/sub/path

fails to load because the app attempts to load runtime.js here:

http://localhost:8100/page/sub/path/runtime.js

my base href is currently set to ./

When i inspect the html source, the script tags are formatted as follows:

<script type="text/javascript" src="runtime.js"></script>

If i attempt to load a page directly at the root, the application loads ok without issue like so:

http://localhost:8100 loads OK

http://localhost:8100/page loads OK

So again to recap, the app only fails to load the js assets at a sub path.

Any idea where to begin troubleshooting?


Solution

  • For anyone running into this same problem, i have the answer.

    I am not sure when or why, but my base href was set incorrectly and this was the problem.

    I changed my base href from ./ to / and this solved my problem.