Skip to content

Commit 116841e

Browse files
committed
fix: default route resolution + docs
1 parent 221e1df commit 116841e

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

Diff for: README.md

+16
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,19 @@ export default {
8080
}
8181
}
8282
```
83+
84+
## Navigating
85+
86+
This package provides 2 methods for navigation, `$navigator.navigate` and `$navigator.back`
87+
88+
`$navigator.navigate(to, options)` is used for all forward navigation
89+
* `to` is the path to navigate to (ex.: `/home`)
90+
* `options` is an optional object, which accepts all options supported by [Manual Routing](https://nativescript-vue.org/en/docs/routing/manual-routing/#navigateto)
91+
92+
For example, given you are on a Login page, and successfully log in you would navigate to the Home page with
93+
```js
94+
this.$navigator.navigate('/home', { clearHistory: true })
95+
```
96+
Note that we used `clearHistory: true` to prevent the back button from going back to the login page.
97+
98+
`$navigator.back(options, backstackEntry)` is an alias to [`$navigateBack`](https://nativescript-vue.org/en/docs/routing/manual-routing/#navigatebackoptions-backstackentry--null)

Diff for: components/Navigator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default {
3838
_currentEntry = value
3939
if (value && value.resolvedPage) {
4040
self.$navigator._updatePath(
41-
value.resolvedPage.__path || value.resolvedPage.path || ''
41+
value.resolvedPage.__path || self.defaultRoute || ''
4242
)
4343
}
4444
},

Diff for: index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ export default function install(Vue, {routes}) {
1818

1919
Vue.prototype.$navigator = new Vue({
2020
data: {
21-
path: '',
21+
path: false,
22+
defaultPath: '/'
2223
},
2324
computed: {
2425
route() {
25-
return routes[this.path]
26+
return routes[this.path || this.defaultPath]
2627
},
2728
},
2829
methods: {
29-
_resolveComponent() {
30+
_resolveComponent(defaultPath) {
31+
if(defaultPath) this.defaultPath = defaultPath
32+
3033
if (this.route) {
3134
return this.route.component
3235
}
@@ -47,6 +50,9 @@ export default function install(Vue, {routes}) {
4750
}
4851

4952
this.$navigateTo(matchedRoute.component, options)
53+
},
54+
back(...args) {
55+
this.$navigateBack.call(this, args)
5056
}
5157
},
5258
})

Diff for: package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)