使用 Angular2 从 url 检索哈希片段 [英] Retrieve hash fragment from url with Angular2
本文介绍了使用 Angular2 从 url 检索哈希片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于这个 url 结构(我无法控制),我如何使用 Angular2 检索哈希片段?
Given this url structure (over which I have no control), how can I retrieve the hash fragment using Angular2?
http://your-redirect-uri#access_token=ACCESS-TOKEN
我的路由器确实路由到了正确的组件,但是 oauth
之后的所有内容都被废弃了,我在 request.params 或 location.path 中找不到哈希片段.命中注定??
My router does route to the correct component, but everything after oauth
get scrapped and I can't find the hash fragment in request.params or location.path. Doomed??
路由器配置:
@RouteConfig([
{path: '/welcome', name: 'Welcome', component: WelcomeComponent, useAsDefault: true},
{path: '/landing/oauth', name: 'Landing', component: LandingComponent} // this one
])
推荐答案
对于那些仍在寻找的人:
For those still looking :
import { ActivatedRoute } from '@angular/router';
export class MyComponent {
constructor(
private route: ActivatedRoute,
) { }
myfunction(){
this.route.fragment.subscribe((fragment: string) => {
console.log("My hash fragment is here => ", fragment)
})
}
}
这篇关于使用 Angular2 从 url 检索哈希片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文