2016-04-16 15 views
10

इस यूआरएल संरचना (जिस पर मैं कोई नियंत्रण नहीं) को देखते हुए के साथ यूआरएल से हैश टुकड़ा पुनः प्राप्त कैसे मैं Angular2 का उपयोग कर हैश टुकड़ा प्राप्त कर सकते हैं? बाद oauth खत्म कर दिया हो और मैं request.params या location.path में हैश टुकड़ा नहीं मिल सकता है, Angular2

http://your-redirect-uri#access_token=ACCESS-TOKEN

मेरे रूटर सही घटक के लिए रास्ते में है, लेकिन सब कुछ करता है। बर्बाद ??

रूटर config:

@RouteConfig([ 
{path: '/welcome', name: 'Welcome', component: WelcomeComponent, useAsDefault: true}, 
{path: '/landing/oauth', name: 'Landing', component: LandingComponent} // this one 

])

उत्तर

19

उन लोगों के लिए अभी भी देख:

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) 
    }) 
    } 
} 

मैं इस विन्यास के साथ यह तय

1

मैं response_type = token साथ OAuth सर्वर का अनुरोध करके एक ही समस्या थी, और जो %REDIRECT_URI%#access_token=:access_token&token_type=:token_type&expires_in=:expires_in पर रीडायरेक्ट।

समस्या डिफ़ॉल्ट रूप से उप-यूआरएल की सीधी पहुंच को रूट नहीं किया जाता है: आपके मामले में, %BASE_URL%/landing/oauthLandingComponent घटक पर रीडायरेक्ट नहीं किया जाएगा।

import { bootstrap } from '@angular/platform-browser-dynamic'; 
import { provide } from '@angular/core'; 
import { APP_BASE_HREF } from '@angular/common'; 
import { ROUTER_PROVIDERS } from '@angular/router'; 

import { AppComponent } from './components/app/app.component'; 

bootstrap(AppComponent, [ 
    ROUTER_PROVIDERS, 
    provide(APP_BASE_HREF, { useValue: '/' }) // this line 
]);