使用 Electron 时,我应该如何为 Angular 2 配置 base href? [英] How should I configure the base href for Angular 2 when using Electron?

查看:28
本文介绍了使用 Electron 时,我应该如何为 Angular 2 配置 base href?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Angular 2 的引导过程中在 HTML 或 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'].

我尝试只使用 这篇博文,但 Angular 仍然抱怨未设置 base href.

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 配置 base href?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆