使用Electron时应如何配置Angular 2的基本href? [英] How should I configure the base href for Angular 2 when using Electron?
问题描述
我需要在Angular 2的引导过程中在HTML中设置<base>
或在APP_BASE_HREF
中设置,以不引发异常.如果我设置了其中一个,则Electron
会从文件系统的角度考虑,在尝试匹配路由时会在browser_adapter.ts
中引发异常:
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:
例外:错误:未捕获(按承诺):无法匹配任何路由. 当前细分:"C:".可用的路线:['/dashboard','/accounts'].
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.
推荐答案
由于href
属性可以采用相对路径,并且感谢@DavidC和@ChristianRondeau在对问题的评论中进行验证,因此它应该像这样工作:
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="./">
这篇关于使用Electron时应如何配置Angular 2的基本href?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!