1- import { Frame , NavigationEntry , Page } from '@nativescript/core' ;
1+ import {
2+ EventData ,
3+ Frame ,
4+ NavigationEntry ,
5+ Page ,
6+ ViewBase ,
7+ } from '@nativescript/core' ;
28import { App , Component , Ref , nextTick , unref } from '@vue/runtime-core' ;
39import { NSVElement , NSVRoot } from '../dom' ;
410import { CreateNativeViewProps , createNativeView } from '../runtimeHelpers' ;
@@ -75,19 +81,17 @@ export function $navigateTo<P = any>(
7581 const root = new NSVRoot ( ) ;
7682 let isReloading = false ;
7783
78- const attachDisposeCallback = ( page : Page ) => {
79- const dispose = page . disposeNativeView ;
84+ const disposeCallback = ( args : EventData ) => {
85+ const page = args . object as Page ;
8086
81- page . disposeNativeView = ( ) => {
82- dispose . call ( page ) ;
83-
84- // if we are reloading, don't unmount the view, as the reload will unmount/remount it.
85- if ( ! isReloading ) {
86- view . unmount ( ) ;
87- view = null ;
88- }
89- } ;
87+ // if we are reloading, don't unmount the view, as the reload will unmount/remount it.
88+ if ( ! isReloading && view ) {
89+ page . off ( ViewBase . disposeNativeViewEvent , disposeCallback ) ;
90+ view . unmount ( ) ;
91+ view = null ;
92+ }
9093 } ;
94+
9195 const reloadPage = ( ) => {
9296 if ( isReloading ) {
9397 return ;
@@ -106,7 +110,8 @@ export function $navigateTo<P = any>(
106110 isReloading = true ;
107111 view . unmount ( ) ;
108112 view . mount ( root ) ;
109- attachDisposeCallback ( view . nativeView ) ;
113+ view . nativeView . off ( ViewBase . disposeNativeViewEvent , disposeCallback ) ;
114+ view . nativeView . on ( ViewBase . disposeNativeViewEvent , disposeCallback ) ;
110115
111116 const originalTransition = frame . currentEntry . transition ;
112117 // replace current page
@@ -133,7 +138,8 @@ export function $navigateTo<P = any>(
133138 } ) ;
134139
135140 view . mount ( root ) ;
136- attachDisposeCallback ( view . nativeView ) ;
141+ view . nativeView . off ( ViewBase . disposeNativeViewEvent , disposeCallback ) ;
142+ view . nativeView . on ( ViewBase . disposeNativeViewEvent , disposeCallback ) ;
137143
138144 frame . navigate ( {
139145 ...options ,
0 commit comments