@@ -14,6 +14,9 @@ export default (bus, store, moduleName, keyName) => {
14
14
'navigation/BACK' : ( state , { to, from, count} ) => {
15
15
state . routes . splice ( state . routes . length - count , count )
16
16
} ,
17
+ 'navigation/REPLACE' : ( state , { to, from, name} ) => {
18
+ state . routes . splice ( Routes . length - 1 , 1 , name )
19
+ } ,
17
20
'navigation/REFRESH' : ( state , { to, from} ) => {
18
21
} ,
19
22
'navigation/RESET' : ( state ) => {
@@ -26,29 +29,40 @@ export default (bus, store, moduleName, keyName) => {
26
29
const forward = ( name , toRoute , fromRoute ) => {
27
30
const to = { route : toRoute }
28
31
const from = { route : fromRoute }
29
- const route = store ? store . state [ moduleName ] . routes : Routes
32
+ const routes = store ? store . state [ moduleName ] . routes : Routes
30
33
// if from does not exist, it will be set null
31
- from . name = route [ route . length - 1 ] || null
34
+ from . name = routes [ routes . length - 1 ] || null
32
35
to . name = name
33
- store ? store . commit ( 'navigation/FORWARD' , { to, from, name} ) : route . push ( name )
34
- window . sessionStorage . VUE_NAVIGATION = JSON . stringify ( route )
36
+ store ? store . commit ( 'navigation/FORWARD' , { to, from, name} ) : routes . push ( name )
37
+ window . sessionStorage . VUE_NAVIGATION = JSON . stringify ( routes )
35
38
bus . $emit ( 'forward' , to , from )
36
39
}
37
40
const back = ( count , toRoute , fromRoute ) => {
38
41
const to = { route : toRoute }
39
42
const from = { route : fromRoute }
40
- const route = store ? store . state [ moduleName ] . routes : Routes
41
- from . name = route [ route . length - 1 ]
42
- to . name = route [ route . length - 1 - count ]
43
- store ? store . commit ( 'navigation/BACK' , { to, from, count} ) : route . splice ( Routes . length - count , count )
44
- window . sessionStorage . VUE_NAVIGATION = JSON . stringify ( route )
43
+ const routes = store ? store . state [ moduleName ] . routes : Routes
44
+ from . name = routes [ routes . length - 1 ]
45
+ to . name = routes [ routes . length - 1 - count ]
46
+ store ? store . commit ( 'navigation/BACK' , { to, from, count} ) : routes . splice ( Routes . length - count , count )
47
+ window . sessionStorage . VUE_NAVIGATION = JSON . stringify ( routes )
45
48
bus . $emit ( 'back' , to , from )
46
49
}
50
+ const replace = ( name , toRoute , fromRoute ) => {
51
+ const to = { route : toRoute }
52
+ const from = { route : fromRoute }
53
+ const routes = store ? store . state [ moduleName ] . routes : Routes
54
+ // if from does not exist, it will be set null
55
+ from . name = routes [ routes . length - 1 ] || null
56
+ to . name = name
57
+ store ? store . commit ( 'navigation/REPLACE' , { to, from, name} ) : routes . splice ( Routes . length - 1 , 1 , name )
58
+ window . sessionStorage . VUE_NAVIGATION = JSON . stringify ( routes )
59
+ bus . $emit ( 'replace' , to , from )
60
+ }
47
61
const refresh = ( toRoute , fromRoute ) => {
48
62
const to = { route : toRoute }
49
63
const from = { route : fromRoute }
50
- const route = store ? store . state [ moduleName ] . routes : Routes
51
- to . name = from . name = route [ route . length - 1 ]
64
+ const routes = store ? store . state [ moduleName ] . routes : Routes
65
+ to . name = from . name = routes [ routes . length - 1 ]
52
66
store ? store . commit ( 'navigation/REFRESH' , { to, from} ) : null
53
67
bus . $emit ( 'refresh' , to , from )
54
68
}
@@ -58,15 +72,19 @@ export default (bus, store, moduleName, keyName) => {
58
72
bus . $emit ( 'reset' )
59
73
}
60
74
61
- const record = ( toRoute , fromRoute ) => {
75
+ const record = ( toRoute , fromRoute , replaceFlag ) => {
62
76
const name = getKey ( toRoute , keyName )
63
- const toIndex = Routes . lastIndexOf ( name )
64
- if ( toIndex === - 1 ) {
65
- forward ( name , toRoute , fromRoute )
66
- } else if ( toIndex === Routes . length - 1 ) {
67
- refresh ( toRoute , fromRoute )
77
+ if ( replaceFlag ) {
78
+ replace ( name , toRoute , fromRoute )
68
79
} else {
69
- back ( Routes . length - 1 - toIndex , toRoute , fromRoute )
80
+ const toIndex = Routes . lastIndexOf ( name )
81
+ if ( toIndex === - 1 ) {
82
+ forward ( name , toRoute , fromRoute )
83
+ } else if ( toIndex === Routes . length - 1 ) {
84
+ refresh ( toRoute , fromRoute )
85
+ } else {
86
+ back ( Routes . length - 1 - toIndex , toRoute , fromRoute )
87
+ }
70
88
}
71
89
}
72
90
0 commit comments