You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The easiest way to do routing in NativeScript-Vue is using the convenience functions
7
-
`$navigateTo`, `$navigateBack`, and `$showModal`.
6
+
The easiest way to do routing in NativeScript-Vue is by using any of the following convenience functions:
8
7
9
-
### `$navigateTo`
10
-
11
-
Suppose you have components `Master` and `Detail` and want to navigate from `Master` to `Detail`,
12
-
then you have two ways to call `$navigateTo`: in the view, or in a method:
8
+
*[`$navigateTo`](#navigateto)
9
+
*[`$navigateBack`](#navigateback)
10
+
*[`$showModal`](#showmodal)
13
11
14
-
The `$navigateTo` accepts a second `options` parameter, which allows you to specify the transition as well as pass in a `context` object which will be used when instantiating the target component. This is useful when you want to pass props to the target component. For example:
12
+
> All examples on this page discuss how to handle routing between the `Master` and `Detail` components of a mobile app.
15
13
16
-
```js
17
-
this.$navigateTo(Detail, {
18
-
transition: {},
19
-
transitionIOS: {},
20
-
transitionAndroid: {},
21
-
22
-
context: {
23
-
propsData: {
24
-
foo:'bar',
25
-
}
26
-
}
27
-
});
28
-
```
14
+
### `$navigateTo`
29
15
30
-
To read more about the options you can pass [head over to the documentation for NavigationEntry](https://docs.nativescript.org/api-reference/interfaces/_ui_frame_.navigationentry).
16
+
You can call `$navigateTo` in the view or in a method.
31
17
32
18
#### In the view
33
19
34
-
Expose the `Detail` component through a `data` property in the `Master` component and invoke`$navigateTo(<propertyName>)` in the view directly.
20
+
In the `Master` component, use a `data` property to expose the `Detail` component. Invoke`$navigateTo(<propertyName>)` in the view directly.
35
21
36
-
```vue
22
+
```Vue
37
23
const Vue = require('nativescript-vue');
38
24
39
25
const Master = {
@@ -71,9 +57,9 @@ new Vue({
71
57
72
58
#### In a method
73
59
74
-
Bind a button to a method and use `this.$navigateTo(Detail)` to navigate to the `Detail` component in that method,
60
+
Bind a button to a method and use `this.$navigateTo(Detail)` to navigate to the `Detail` component.
75
61
76
-
```vue
62
+
```Vue
77
63
const Master = {
78
64
template: `
79
65
<Page>
@@ -103,11 +89,36 @@ const Detail = {
103
89
};
104
90
```
105
91
92
+
#### Passing props to the target component
93
+
94
+
`$navigateTo` accepts a second `options` parameter. You can use the parameter to:
95
+
96
+
* set the transition
97
+
* pass a `context` object with props to be used when instantiating the target component
98
+
99
+
For example:
100
+
101
+
```JavaScript
102
+
this.$navigateTo(Detail, {
103
+
transition: {},
104
+
transitionIOS: {},
105
+
transitionAndroid: {},
106
+
107
+
context: {
108
+
propsData: {
109
+
foo:'bar',
110
+
}
111
+
}
112
+
});
113
+
```
114
+
115
+
For more information about the options that you can pass, see [`NavigationEntry`](https://docs.nativescript.org/api-reference/interfaces/_ui_frame_.navigationentry).
116
+
106
117
### `$navigateBack`
107
118
108
-
Add a button to the `Detail` component, which simply triggers the globally exposed `$navigateBack` function.
119
+
In the `Detail` component, add a button that triggers the globally exposed `$navigateBack` function.
109
120
110
-
```vue
121
+
```Vue
111
122
const Detail = {
112
123
template: `
113
124
<Page>
@@ -122,12 +133,55 @@ const Detail = {
122
133
123
134
### `$showModal`
124
135
125
-
If you want to show the `Detail` page modally, simply replace `$navigateTo` by `$showModal`.
126
-
As before, you can call this method either from the view or a function.
136
+
Use `$showModal` to show the `Detail` page modally. This function behaves similarly to `$navigateTo`.
127
137
128
-
To close the modal, call `$modal.close`.
138
+
You can call `$showModal` in the view or in a method. To close the modal, call `$modal.close`.
129
139
130
-
```vue
140
+
#### In the view
141
+
142
+
In the `Master` component, use a `data` property to expose the `Detail` component. Invoke `$showModal(<propertyName>)` in the view directly.
Bind a button to a method and use `this.$showModal(Detail)` to navigate to the `Detail` component.
183
+
184
+
```Vue
131
185
const Master = {
132
186
template: `
133
187
<Page>
@@ -159,15 +213,13 @@ const Detail = {
159
213
160
214
#### Passing props to the modal
161
215
162
-
Properties can be passed to the modal by including `propsData` inside a `context` object passed as an option when calling `$showModal`.
163
-
164
-
If we were to pass an `id` prop to the Detail component from the previous Master/Detail example, we would show the modal using:
216
+
`$showModal` accepts a second parameter. You can use the parameter to pass in a `context` object containing `propsData` to the target component. For example:
0 commit comments