ngRoute设置基本URL为所有路由 [英] ngRoute set base url for all routes

查看:93
本文介绍了ngRoute设置基本URL为所有路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能一个基础URL添加到所有航线的AngularJS应用程序?在服务器上的本质改变其位置(那种,如果是有道理的......所以它不会通过'/',而是通过'/东西/').

Is it possible to add a base url to all routes in an AngularJS app? Essentially changing its location on the server (kind of, if that makes sense... so it would be accessed not via '/' but via '/something/').

要添加一些情况下,我试图把背后的一些验证现有的应用角度,以使应用程序将现在的地址说 HTTP访问:// mysite的/安全登录成功后。

To add some context, I am trying to place an existing Angular app behind some authentication such that the app would now be accessed at address say http://mysite/secure after successful login.

问题是如果我在 HTTP加载应用程序:// mysite的/安全它工作正常(服务器将明显起到了正确的页面),但点击任何链接将导致页面重载和路线的http:// mysite的/#NEWPAGE 而不是的http:// mysite的/安全/# NEWPAGE

The problem is if I was to load the app at http://mysite/secure it works fine (the server will obviously serve up the correct page), but clicking any link would result in a page reload and route to http://mysite/#newpage instead of http://mysite/secure/#newpage.

无需添加/安全/所有的路线和链接元素是这可能吗?欢呼声,如果很抱歉没有措辞好。

Without adding /secure/ to all of the routes and link element is this possible? Cheers, sorry if that is not worded well.

推荐答案

设置<碱基GT; HTML5标签可能的帮助。从文档这里

Setting the <base> HTML5 tag might help. From the documentation here:

相对链接

请务必检查所有相关链接,图片,脚本等等。你必须要么在你的主HTML文件(&LT头指定的URL基地;基地的HREF =/我的基地&GT ; ),或者你必须使用绝对路径(从/)随处可见,因为相对URL会使用文档,这往往是从应用程序的根目录下不同的初始绝对URL解析为绝对URL。

Be sure to check all relative links, images, scripts etc. You must either specify the url base in the head of your main html file (<base href="/my-base">) or you must use absolute urls (starting with /) everywhere because relative urls will be resolved to absolute urls using the initial absolute url of the document, which is often different from the root of the application.

运行与文档根目录启用了历史API应用角度大力鼓励,因为它需要所有相关环节的问题护理。

Running Angular apps with the History API enabled from document root is strongly encouraged as it takes care of all relative link issues.

这篇关于ngRoute设置基本URL为所有路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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