I need to either set <base>
in the HTML or APP_BASE_HREF
during the bootstrap for Angular 2 to not throw exceptions. If I set either of these then Electron
, thinking in terms of the file system, throws exceptions in browser_adapter.ts
when trying to match a route:
EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'C:'. Available routes: ['/dashboard', '/accounts'].
I tried using just the HashLocationStrategy
mentioned in this blog post, but Angular still complains about the base href not being set.
The <base href="/"> tells the Angular router what is the static part of the URL. The router then only modifies the remaining part of the URL. Now that we've set the our base href tag, we can then move on to defining some routes without your route module file or your app.
The base href is the URL prefix that should be preserved when generating and recognizing URLs.
The <base href> is used as the default base URL (see source code) when generating HTML5 style URLs for your web app. Additionally, it "specifies a base path for resolving relative URLs to assets such as images, scripts, and style sheets," namely your Angular distribution.
Since the href
attribute can take a relative path and thanks to @DavidC and @ChristianRondeau in the comments on the question for verifying, it should work like this:
<base href="./">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With