How should I configure the base href for Angular 2

2019-04-03 22:56发布

问题:

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.

回答1:

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="./">