我正在使用Angular 8进行NativeScript 6项目。
我要在用户登录后清除路由器历史记录。
这是我尝试过的:
public onLogin(){
this.registerUserCredentialsService
.registerUserCredentials(this.username, this.password)
.then(() => {
this.router.navigate(['home-page'], { clearHistory: true });
});
}
我不断收到此错误:
ERROR in src/app/register-user-credentials.component.ts(33,55): error TS2345: Argument of type '{ clearHistory: boolean; }' is not assignable to parameter of type 'NavigationExtras'.
Object literal may only specify known properties, and 'clearHistory' does not exist in type 'NavigationExtras'.
How can I clear the router history?
答案 0 :(得分:3)
尝试使用RouterExtensions
代替Router
import { RouterExtensions } from "nativescript-angular/router";
...
constructor(
private routerExtensions: RouterExtensions
) {}
...
this.routerExtensions.navigate(['home-page'], { clearHistory: true });
答案 1 :(得分:0)
您也可以使用queryParams,如路由器选项Angular NavigationExtras的文档中所述。您可以像这样设置。
this.router.navigate(['home-page'], {queryParams: {clearHistory: true }});