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
Copy file name to clipboardExpand all lines: docs_src/content/guide/10-routing.md
+103-2Lines changed: 103 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Routing in Svelte Native is designed to be very similar and the `svelte-native`
11
11
Specify the destination page with the mandatory `page` option. This takes a `Svelte` component class.
12
12
13
13
```html
14
-
<!--{ filename: App.svelte } -->
14
+
<!--{ filename: 'App.svelte' }-->
15
15
<page>
16
16
<actionBartitle="Master" />
17
17
<stackLayout>
@@ -30,7 +30,7 @@ Specify the destination page with the mandatory `page` option. This takes a `Sve
30
30
You can specify the props used to create the Svelte component using the `props` option.
31
31
32
32
```html
33
-
<!--{ filename: App.svelte } -->
33
+
<!--{ filename: 'App.svelte' }-->
34
34
<page>
35
35
<actionBartitle="Master" />
36
36
<stackLayout>
@@ -76,8 +76,109 @@ For more information about the options that you can pass, see [NavigationEntry](
76
76
77
77
### goBack
78
78
79
+
To navigate back to a previous page, use the `goBack` function.
80
+
81
+
```html
82
+
<!--{filename: 'App.svelte'}-->
83
+
<page>
84
+
<actionBartitle="Detail"/>
85
+
<stackLayout>
86
+
<buttontext="Back to Master"on:tap="{goBack}" />
87
+
</stackLayout>
88
+
</page>
89
+
90
+
<script>
91
+
import { goBack } from'svelte-native'
92
+
</script>
93
+
```
94
+
95
+
To cause the back to happen on another frame, pass in a frame reference or id to the `frame` option.
96
+
97
+
```js
98
+
goBack({frame:'sub-nav-frame'})
99
+
```
100
+
101
+
`goBack` by default goes back to the previous page, you can go back multiple pages if you specify a `page` reference in options.
102
+
103
+
```js
104
+
goBack({to: options_page_ref})
105
+
```
106
+
79
107
### showModal
80
108
109
+
To show a page or component modally use the `showModal` function. Specify the page to open using the `page` option and props using the `props` option (just like in [navigate](#navigate))
The other options available correspond directly to those in [ShowModalOptions](https://docs.nativescript.org/api-reference/interfaces/_ui_core_view_base_.showmodaloptions) and are passed through to the underlying NativeScript showModal method.
140
+
141
+
The `showModal` function returns a promise which resolves to whatever is passed to `closeModal`
142
+
143
+
> **NOTE** The modal is opened in a new navigation context. If you want to allow navigation within the modal, or show an action bar, you will need to wrap the target page in a `frame` element. If you don't need any navigation within the modal then this won't be necessary.
144
+
145
+
146
+
### closeModal
147
+
148
+
The `closeModal` function closes the current modal view and optionally returns a value to the caller of the original `showModal` via a promise result.
149
+
150
+
```html
151
+
<!--{ filename: 'App.svelte'} -->
152
+
<page>
153
+
<actionBartitle="Master" />
154
+
<stackLayout>
155
+
<buttontext="Open Modal"on:tap="{launchModal}" />
156
+
<labeltext="{modalResult}" />
157
+
</stackLayout>
158
+
</page>
159
+
<script>
160
+
importDetailPagefrom'./DetailPage.svelte'
161
+
import { showModal } from'svelte-native'
162
+
163
+
let modalResult ="Waiting for modal"
164
+
asyncfunctionlaunchModal() {
165
+
let result =awaitshowModal({ page: DetailPage, props: { msg:'hi' } })
166
+
modalResult =`got result: ${result}`
167
+
}
168
+
</script>
169
+
```
170
+
171
+
```html
172
+
<!--{filename: "DetailPage.svelte" }-->
173
+
<frameid="detail-page-frame">
174
+
<page>
175
+
<buttontext="Close me"on:tap="{ () => closeModal('hi from modal') }" />
0 commit comments