带有Cordova IOS的​​Angular 2应用库href [英] Angular 2 app base href with Cordova IOS

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

问题描述

我正在将Angular 2与cordova一起开发应用程序.我已经使用角度cli来构建应用程序.现在,关于IOS应用程序,我在启动时遇到了一些路由问题.基本href似乎设置错误.如果使用以下方法设置基本href:<base href="/" target="_blank">,则不会加载该应用程序.如果在使用以下命令引导应用程序时设置了基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

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?

我使用以下方法解决了这个问题:在索引html中使用<base href="./" target="_blank">并删除了provide(APP_BASE_HREF, {useValue:'/'}).这样,我必须根据我将应用程序部署到android还是ios来设置更改基本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和images文件加载都是正确的.

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

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

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