使用Electron时应如何配置Angular 2的基本href? [英] How should I configure the base href for Angular 2 when using Electron?

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

问题描述

我需要在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屋!

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