带有 Cordova IOS 的 Angular 2 app base href [英] Angular 2 app base href with Cordova IOS

查看:26
本文介绍了带有 Cordova IOS 的 Angular 2 app base href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular 2 和cordova 开发一个应用程序.我已经使用 angular cli 来构建应用程序.当涉及到 IOS 应用程序时,我现在在启动时遇到了一些路由问题.基本 href 似乎设置错误.如果我使用以下方法设置 base href:<base href="/" target="_blank"> 应用程序不会加载.如果在使用以下命令引导应用程序时设置了 base href:...,provide(APP_BASE_HREF, {useValue:'/'}), ... 应用程序将加载,但出现以下异常:

I am developing an application using Angular 2 with cordova. I have used the angular cli to build the appplication. I have now ran into some routing issues on startup when it comes to the IOS application. The base href seems to be set wrong. If I set the base href using: <base href="/" target="_blank"> the application doesn't load. If the base href is set when I bootstrap the application using: ...,provide(APP_BASE_HREF, {useValue:'/'}), ... the application will load but I get the following exception:

例外:错误:未捕获(承诺):错误:无法匹配任何路线:'var/containers/Bundle/Application/3C8966ED-7DDD-4309-8C18-10B778C5AE15/test.app/www'

EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'var/containers/Bundle/Application/3C8966ED-7DDD-4309-8C18-10B778C5AE15/test.app/www'

因此应用程序无法正常运行,因为在应用程序启动时没有加载关键文件.对于android,我遇到了同样的问题,但我找到了解决方案,在以下问题中设置基本href android 解决方案.有没有人遇到过这个问题并有解决方案?

So the application can't function properly since there are critical files that don't get loaded on the start of the application. For android I encountered the same problem but I found the solution, to set the base href in the following question android solution. Have anybody encountered this problem and have a solution?

我用这个解决了这个问题:<base href="./" target="_blank">in index html并删除<代码>提供(APP_BASE_HREF,{useValue:'/'}).通过这种方式,我必须根据我是将应用程序部署到 android 还是 ios 来设置更改 base href.

I solved the problem by using this: <base href="./" target="_blank">in index html and remove the provide(APP_BASE_HREF, {useValue:'/'}). This way I have to set change the base href depending if I'm deploying the app to android or ios.

推荐答案

我设置为

<base href="www">

并且所有 css、js 和图像文件加载都正确.

and all css, js and images file loading are correct.

这篇关于带有 Cordova IOS 的 Angular 2 app base href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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