在我的标题组件中,我有一个登录按钮,可以将我登录到第三方网站。应用程序sc2使用callbackURL在Header组件中初始化。在标题中,我得到一个LoginURL,用于连接到sc2。对于loginURL,我可以添加一个状态,在我的例子中只是一个字符串,其中包含我当前页面的id,这将返回回调URL的参数。问题是Header永远不会被状态更新,因为回调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);
}
标头组件
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(); }
答案 0 :(得分:0)
区域问题,因此您可以使用此方法
import { ApplicationRef } from '@angular/core';
constructor(
private _applicationRef: ApplicationRef) {}
this.router.navigate(['/router']).then(() => {
this._applicationRef.tick();
});