Что вы хотите сделать, так это использовать CustomRouteReuseStrategy
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot } from '@angular/router';
import { NSLocationStrategy } from 'nativescript-angular/router/ns-location-strategy';
import { NSRouteReuseStrategy } from 'nativescript-angular/router/ns-route-reuse-strategy';
@Injectable()
export class CustomRouteReuseStrategy extends NSRouteReuseStrategy {
constructor(location: NSLocationStrategy) {
super(location);
}
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
return false;
}
}
и внутри вашего AppModule вы хотите поместить его как поставщика
import { NgModule, NgModuleFactoryLoader, NO_ERRORS_SCHEMA } from "@angular/core";
import { RouteReuseStrategy } from "@angular/router";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppRoutingModule } from "./app-routing.module";
import { CustomRouteReuseStrategy } from "./custom-router-strategy";
import { AppComponent } from "./app.component";
@NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule
],
declarations: [
AppComponent
],
providers: [
{
provide: RouteReuseStrategy,
useClass: CustomRouteReuseStrategy
}
],
schemas: [
NO_ERRORS_SCHEMA
]
})
export class AppModule { }
вот пример на play.nativescript.org
https://play.nativescript.org/?template=play-ng&id=AspHuI < / а>
(Я этого не делал, я просто передаю информацию, которую узнал.)
Кроме того, если вы хотите, чтобы только определенные страницы повторно использовали стратегию маршрутизации, вам потребуется внести дополнительные изменения в код.
shouldReuseRoute(future: ActivatedRouteSnapshot, current: ActivatedRouteSnapshot): boolean {
// first use the global Reuse Strategy evaluation function,
// which will return true, when we are navigating from the same component to itself
let shouldReuse = super.shouldReuseRoute(future, current);
// then check if the noReuse flag is set to true
if (shouldReuse && current.data.noReuse) {
// if true, then don't reuse this component
shouldReuse = false;
}
а затем вы можете передать noReuse в качестве параметра маршрута, чтобы у вас была дополнительная проверка помимо значения по умолчанию "shouldReuse"
Надеюсь это поможет!
person
Zuriel
schedule
14.02.2019