Skip to content

Commit b58b36b

Browse files
committed
fix: defaultPath per navigator instance
1 parent 99f9e36 commit b58b36b

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

components/Navigator.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export default {
2929
},
3030
created() {
3131
this.defaultRouteComponent = this.$navigator._resolveComponent(
32-
this.$props.defaultRoute
32+
this.$props.defaultRoute,
33+
this.$props.id
3334
)
3435
},
3536
methods: {

index.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import Navigator from './components/Navigator'
22

33
export default function install(Vue, {routes}) {
4+
let appRoot;
5+
const start = Vue.prototype.$start
6+
Vue.prototype.$start = function () {
7+
appRoot = this
8+
start.call(this)
9+
}
410
Vue.component('Navigator', Navigator)
511

612
Object.keys(routes).map(path => {
@@ -20,24 +26,29 @@ export default function install(Vue, {routes}) {
2026
data: {
2127
path: false,
2228
paths: {},
23-
defaultPath: '/'
29+
defaultPaths: {},
2430
},
2531
computed: {
2632
route() {
27-
return routes[this.path || this.defaultPath]
33+
return this.routes('navigator')
34+
},
35+
routes() {
36+
return id => routes[this.paths[id] || this.defaultPaths[id]]
2837
},
2938
},
3039
methods: {
31-
_resolveComponent(defaultPath) {
32-
if(defaultPath) this.defaultPath = defaultPath
40+
_resolveComponent(defaultPath, id) {
41+
if (defaultPath) {
42+
this.$set(this.defaultPaths, id, defaultPath)
43+
}
3344

34-
if (this.route) {
35-
return this.route.component
45+
if (this.routes(id)) {
46+
return this.routes(id).component
3647
}
3748
return false
3849
},
3950
_updatePath(path, id = 'navigator') {
40-
if(id === 'navigator') {
51+
if (id === 'navigator') {
4152
this.path = path
4253
}
4354
this.$set(this.paths, id, path)
@@ -48,17 +59,18 @@ export default function install(Vue, {routes}) {
4859

4960
if (!matchedRoute) {
5061
if (TNS_ENV === 'development') {
51-
throw new Error(`Navigating to a route that does not exist: ${to}`)
62+
throw new Error(`[Navigator] Navigating to a route that does not exist: ${to}`)
5263
}
5364
return false
5465
}
5566

56-
options = Object.assign({ frame: 'navigator' }, options)
67+
options = Object.assign({frame: 'navigator'}, options)
5768

5869
return this.$navigateTo(matchedRoute.component, options)
70+
.catch(err => console.log(`[Navigator] Failed to navigate: ${err}`))
5971
},
6072
back(options, ...args) {
61-
options = Object.assign({ frame: 'navigator' }, options)
73+
options = Object.assign({frame: 'navigator'}, options)
6274
return this.$navigateBack.call(this, options, ...args)
6375
}
6476
},

0 commit comments

Comments
 (0)