1
1
import { setFrame , deleteFrame } from '../../util/frame'
2
+ import { PAGE_REF } from './page'
2
3
3
4
export default {
4
- name : 'frame' ,
5
5
props : {
6
6
id : {
7
7
default : 'default'
8
+ } ,
9
+ // injected by the template compiler
10
+ hasRouterView : {
11
+ default : false
12
+ }
13
+ } ,
14
+ data ( ) {
15
+ return {
16
+ pageRoutes : [ ]
8
17
}
9
18
} ,
10
19
created ( ) {
11
20
setFrame ( this . $props . id , this )
12
- this . cache = { }
13
21
} ,
14
22
destroyed ( ) {
15
23
deleteFrame ( this . $props . id )
16
24
} ,
17
25
render ( h ) {
26
+ let vnode = this . $slots . default
27
+ if ( this . hasRouterView && this . isBackNavigation ) {
28
+ this . isBackNavigation = false
29
+ vnode = this . $el . nativeView . currentPage [ PAGE_REF ] || vnode
30
+ }
31
+
18
32
return h (
19
33
'NativeFrame' ,
20
34
{
21
35
attrs : Object . assign ( { } , this . $attrs , this . $props ) ,
22
36
on : this . $listeners
23
37
} ,
24
- this . $slots . default
38
+ vnode
25
39
)
26
40
} ,
27
41
methods : {
@@ -38,6 +52,10 @@ export default {
38
52
} ,
39
53
40
54
navigate ( entry , back = false ) {
55
+ if ( this . isBackNavigation ) {
56
+ console . log ( 'skipping navigate()' )
57
+ return
58
+ }
41
59
const frame = this . _getFrame ( )
42
60
43
61
if ( back ) {
@@ -58,6 +76,18 @@ export default {
58
76
if ( isBackNavigation ) {
59
77
page . off ( 'navigatedFrom' )
60
78
this . $emit ( 'back' , entry )
79
+
80
+ if ( ! this . hasRouterView ) return
81
+ this . isBackNavigation = true
82
+
83
+ // since this was a page navigation
84
+ // we need to find the previous page's path
85
+ // and navigate back to it
86
+ const lastPageRoute = this . pageRoutes . pop ( )
87
+ while ( this . $router . currentRoute . fullPath !== lastPageRoute ) {
88
+ this . $router . go ( - 1 )
89
+ }
90
+ this . $router . go ( - 1 )
61
91
}
62
92
} )
63
93
entry . create = ( ) => page
0 commit comments