I'm very new to Angularjs, so please excuse me if that's an obvious question. We have an existing Ajgularjs single-page application, that works with data from after the hash. E.g.
我对Angularjs很新,所以请原谅我这是一个显而易见的问题。我们有一个现有的Ajgularjs单页面应用程序,它可以处理哈希后的数据。例如。
http://server/myapp#/user/777?accountid=123&arranger=true
Note the hash.
注意哈希。
This usually works. Unfortunately we ran into some new scenario where we can't use hash (the deep link sometimes goes through an authentication framework outside our control, and it strips down the hash portion of the url). So we also need links without a hash, e.g.
这通常有效。不幸的是,我们遇到了一些我们无法使用哈希的新场景(深层链接有时会通过我们控制之外的身份验证框架,并且它会删除网址的哈希部分)。所以我们还需要没有哈希的链接,例如
http://server/myapp/user/777?accountid=123&arranger=true
Note : I don't mind the exact format, just note it is hash-free.
注意:我不介意确切的格式,只需注意它是无哈希的。
The question: is there some reasonable way to support both approaches, so that the application would react similarly to both types of link? (we need the "hash" format for backwards compatibility with old links, and we need the "hash less" format for the new authentication scenario)
问题是:是否有一些合理的方法来支持这两种方法,以便应用程序对两种类型的链接做出类似的反应? (我们需要“哈希”格式以向后兼容旧链接,我们需要新的身份验证方案的“无哈希”格式)
thanks very much
非常感谢
1 个解决方案
#1
0
On the $location
service, angular makes all parts of the url available to the application.
在$ location服务上,angular使应用程序可以使用url的所有部分。
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var url = $location.url();
// => "/some/path?foo=bar&baz=xoxo"
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var path = $location.path();
// => "/some/path"
// given url http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
var hash = $location.hash();
// => "hashValue"
I'm not sure what your particular situation is, but you might be able to use a $routeChangeStart
event handler (or $stateChangeStart
if using ui-router) to intercept the route and use an appropriate method on $location
to figure out what route you would like to go to. Then set the url to navigate to the decoded route in the application.
我不确定你的具体情况是什么,但是你可以使用$ routeChangeStart事件处理程序(如果使用ui-router则使用$ stateChangeStart)拦截路由并在$ location上使用适当的方法来确定路由你想去。然后设置url以导航到应用程序中的已解码路由。
#1
0
On the $location
service, angular makes all parts of the url available to the application.
在$ location服务上,angular使应用程序可以使用url的所有部分。
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var url = $location.url();
// => "/some/path?foo=bar&baz=xoxo"
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var path = $location.path();
// => "/some/path"
// given url http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
var hash = $location.hash();
// => "hashValue"
I'm not sure what your particular situation is, but you might be able to use a $routeChangeStart
event handler (or $stateChangeStart
if using ui-router) to intercept the route and use an appropriate method on $location
to figure out what route you would like to go to. Then set the url to navigate to the decoded route in the application.
我不确定你的具体情况是什么,但是你可以使用$ routeChangeStart事件处理程序(如果使用ui-router则使用$ stateChangeStart)拦截路由并在$ location上使用适当的方法来确定路由你想去。然后设置url以导航到应用程序中的已解码路由。