如何解决angular:重定向后重新加载页面
我有一个重定向到另一个页面的函数,我希望重定向后的页面也重新加载。
我要在重定向到登录页面后重新加载它。 使用“ window.location.reload()”会重新加载当前页面,该页面是主页,而不是登录页面。 如何重新加载特定页面?
homeComponent.ts
import { Component,OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormGroup,FormBuilder,FormControl,Validators,Form } from '@angular/forms';
import { LoginComponent } from '../authentification/login/login.component';
@Component({
selector: 'app-home',templateUrl: './home.component.html',styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
ngOnInit(): void {
}
constructor(private router: Router) { }
redirection(){
this.router.navigate(['/login']);
}
}
解决方法
你为什么不使用
redirection(){
window.location.href="yourpagedomain/login"
}
它将加载页面。
,在登录页面上,您可以捕获导航事件,然后,如果为true,则可以重新加载表单。希望对您有所帮助:
在您的登录页面上:
OLD:代码错误
||=== Build: Release in Test (compiler: GNU GCC Compiler) ===|
Test/main.cpp|6|warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]|
Test/main.cpp||In function ‘int main()’:|
Test/main.cpp|12|error: ‘snd_pcm_t’ was not declared in this scope; did you mean ‘snd_pcm_info’?|
Test/main.cpp|12|error: ‘handle’ was not declared in this scope|
Test/main.cpp|16|error: ‘SND_PCM_STREAM_PLAYBACK’ was not declared in this scope; did you mean ‘SNDRV_PCM_STREAM_PLAYBACK’?|
Test/main.cpp|16|error: ‘snd_pcm_open’ was not declared in this scope; did you mean ‘snd_pcm_info’?|
Test/main.cpp|17|error: ‘snd_strerror’ was not declared in this scope|
||error: %s\n",snd_strerror(err));|
Test/main.cpp|21|error: ‘SND_PCM_FORMAT_U8’ was not declared in this scope; did you mean ‘SNDRV_PCM_FORMAT_U8’?|
Test/main.cpp|22|error: ‘SND_PCM_ACCESS_RW_INTERLEAVED’ was not declared in this scope; did you mean ‘SNDRV_PCM_ACCESS_RW_INTERLEAVED’?|
Test/main.cpp|20|error: ‘snd_pcm_set_params’ was not declared in this scope; did you mean ‘snd_pcm_sw_params’?|
Test/main.cpp|27|error: ‘snd_strerror’ was not declared in this scope|
||error: %s\n",snd_strerror(err));|
Test/main.cpp|31|error: ‘snd_pcm_writei’ was not declared in this scope|
Test/main.cpp|33|error: ‘snd_pcm_recover’ was not declared in this scope|
Test/main.cpp|35|error: ‘snd_strerror’ was not declared in this scope|
Test/main.cpp|42|error: ‘snd_pcm_drain’ was not declared in this scope|
Test/main.cpp|44|error: ‘snd_strerror’ was not declared in this scope|
Test/main.cpp|45|error: ‘snd_pcm_close’ was not declared in this scope|
||=== Build failed: 17 error(s),1 warning(s) (0 minute(s),0 second(s)) ===|
编辑:此代码有效:
export class LoginPage implements OnInit {
constructor(private router: Router) {
router.events.subscribe(val => {
if (val) {
this.refreshForm(); // Refresh your form
}
});
}
ngOnInit(): void {
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。