在我的标题组件中,我有一个登录按钮,可以将我登录到第三方网站。应用程序sc2在标头组件中使用callbackURL初始化。在标题中,我得到了一个LoginURL,它用于连接到sc2。对于loginURL,我可以添加一个状态,在我的例子中,状态只是一个字符串,其中包含当前页面的id,这将在回调URL的参数中返回。问题是,报头永远不会被状态更新,因为回调URL调用主组件(它加载在路由器出口中),报头本身被加载在主组件之上。我无法使主组件重路由到原始组件。在我将按钮从主组件移到头组件之前,它全部工作,现在发送到主组件的状态没有更新到最后一个页面,所以我不能通过主组件重路由到原始组件。正在使用的页面。我尝试了messageService并使用了localStorage,但就好像头组件从来没有及时更新过一样。回调URL总是指向主组件。我可以直接与标头组件对话吗?
app.component
<app-header> </app-header>
<router-outlet> </router-outlet>
this.api = sc2.Initialize({
app: 'someName.app',
// callbackURL: 'http://localhost/main/',
callbackURL: this.callBackURL,
accessToken: this.accessToken,
scope: ['vote', 'comment']
});
this.loginUrl = this.api.getLoginURL(this.state)page.component.ts
constructor() {
this.newStateService.setState("page")
this.newStateService.setCoinId("pageId")
this.newStateService.changeMessageCoinId(this.coinId)
const params = new HttpParams().set('_id', this.coinId);
}标头component.ts
constructor() {
this.newStateService.currentMessageState
.takeWhile(() => this.alive)
.subscribe(message => {
this.state = message
})
this.newStateService.currentMessageCoinId
.takeWhile(() => this.alive)
.subscribe(message => {
this.coinId= message
})
this.stateText = newStateService.getState();
this.coinId = newStateService.getCoinId(); }发布于 2018-05-26 19:08:14
区域问题,以便您可以使用此方法。
import { ApplicationRef } from '@angular/core';
constructor(
private _applicationRef: ApplicationRef) {}
this.router.navigate(['/router']).then(() => {
this._applicationRef.tick();
});https://stackoverflow.com/questions/48550061
复制相似问题