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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 22 additions & 10 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy