Skip to content

Commit 147794a

Browse files
committed
Finish navigation docs
1 parent 450c439 commit 147794a

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

docs_src/content/guide/10-routing.md

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Routing in Svelte Native is designed to be very similar and the `svelte-native`
1111
Specify the destination page with the mandatory `page` option. This takes a `Svelte` component class.
1212

1313
```html
14-
<!-- { filename: App.svelte } -->
14+
<!--{ filename: 'App.svelte' }-->
1515
<page>
1616
<actionBar title="Master" />
1717
<stackLayout>
@@ -30,7 +30,7 @@ Specify the destination page with the mandatory `page` option. This takes a `Sve
3030
You can specify the props used to create the Svelte component using the `props` option.
3131

3232
```html
33-
<!-- { filename: App.svelte } -->
33+
<!--{ filename: 'App.svelte' }-->
3434
<page>
3535
<actionBar title="Master" />
3636
<stackLayout>
@@ -76,8 +76,109 @@ For more information about the options that you can pass, see [NavigationEntry](
7676

7777
### goBack
7878

79+
To navigate back to a previous page, use the `goBack` function.
80+
81+
```html
82+
<!--{filename: 'App.svelte'}-->
83+
<page>
84+
<actionBar title="Detail"/>
85+
<stackLayout>
86+
<button text="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+
79107
### showModal
80108

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))
110+
111+
```html
112+
<!--{ filename: 'App.svelte'} -->
113+
<page>
114+
<actionBar title="Master" />
115+
<stackLayout>
116+
<button text="Open Modal" on:tap="{launchModal}" />
117+
</stackLayout>
118+
</page>
119+
120+
121+
<script>
122+
import DetailPage from './DetailPage.svelte'
123+
import { showModal } from 'svelte-native'
124+
function launchModal() {
125+
showModal({ page: DetailPage, props: { msg: 'hi' } })
126+
}
127+
</script>
128+
```
129+
130+
```html
131+
<!--{filename: "DetailPage.svelte" }-->
132+
<frame id="detail-page-frame">
133+
<page>
134+
135+
</page>
136+
</frame>
137+
```
138+
139+
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+
<actionBar title="Master" />
154+
<stackLayout>
155+
<button text="Open Modal" on:tap="{launchModal}" />
156+
<label text="{modalResult}" />
157+
</stackLayout>
158+
</page>
159+
<script>
160+
import DetailPage from './DetailPage.svelte'
161+
import { showModal } from 'svelte-native'
162+
163+
let modalResult = "Waiting for modal"
164+
async function launchModal() {
165+
let result = await showModal({ page: DetailPage, props: { msg: 'hi' } })
166+
modalResult = `got result: ${result}`
167+
}
168+
</script>
169+
```
170+
171+
```html
172+
<!--{filename: "DetailPage.svelte" }-->
173+
<frame id="detail-page-frame">
174+
<page>
175+
<button text="Close me" on:tap="{ () => closeModal('hi from modal') }" />
176+
</page>
177+
</frame>
178+
<script>
179+
import { closeModal } from 'svelte-native'
180+
</script>
181+
```
81182

82183

83184

0 commit comments

Comments
 (0)