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
description: Navigate from screen to screen in your app.
3
+
description: Navigate between Pages in your app.
4
4
---
5
-
<!--TODO: Add Preview -->
6
-
<!--TODO: Add flavors -->
7
5
8
6
Navigation in NativeScript is enabled by the `Frame` class.
9
7
10
-
## How to use the Frame class
11
-
12
-
The following sections will show you how to access an instance of the Frame class and use it to navigate between pages in your app.
13
-
8
+
## Examples
14
9
15
10
### Navigating to another page
16
11
17
-
To navigate from one `Page` to another, first obtain the desired [Frame instance](#getting-a-frame-instance).
12
+
To navigate from one `Page` to another, first obtain the desired [Frame instance](#getting-a-frame-instance).
18
13
For simple navigation, call the [navigate](#navigate) method passing along the path of the page to navigate to.
19
14
20
15
```ts
21
-
frame.navigate("~/pages/details/details-page")
16
+
frame.navigate('~/pages/details/details-page')
22
17
```
23
18
24
19
:::tip Note
@@ -27,66 +22,76 @@ For a complete navigation example, have a look at [Setup navigation from home to
27
22
28
23
### Getting a Frame instance
29
24
30
-
The following are some of the ways in which to obtain a Frame:
25
+
The following are some of the ways in which to obtain a Frame instance.
31
26
32
-
1. Calling the static [topmost](#topmost)
27
+
#### Getting the topmost frame
33
28
34
29
```ts
35
-
const frame =Frame.topmost();
30
+
import { Frame } from'@nativescript/core'
31
+
32
+
const frame =Frame.topmost()
36
33
```
37
-
2. Via the `frame` property of a [Page](/ui/page)
34
+
35
+
#### Getting the frame from a Page
38
36
39
37
For example, you can get the current Frame instance from a `tap` event's data as follows:
40
38
41
39
```ts
42
40
onFlickTap(args: EventData): void {
43
-
constbtn=args.objectasButton;
44
-
const frame =btn.page.frame
41
+
constbutton=args.objectasButton;
42
+
const frame =button.page.frame;
45
43
}
46
44
```
47
-
1. Calling the static [getFrameById](#getframebyid) with the id of the frame instance of interest
45
+
46
+
#### Getting a frame by id
48
47
49
48
```ts
50
-
const frame =Frame.getFrameById("frame-id")
49
+
import { Frame } from'@nativescript/core'
50
+
51
+
const frame =Frame.getFrameById('frame-id')
51
52
```
52
53
53
54
### Navigating back
54
55
55
56
To navigate back to the previous page, use the [goBack](#goback) method of the Frame instance.
57
+
56
58
```ts
57
59
frame.goBack()
58
60
```
59
61
60
62
### Avoid navigating back to the previous page
61
63
62
-
To avoid navigating to the previous page, set the [clearHistory](#clearhistory) property of the [NavigationEntry](#navigation-entry-interface) object that you pass to the [navigate](#navigate) method to `true`.
64
+
To avoid navigating to the previous page, set the [clearHistory](#clearhistory) property of the [NavigationEntry](#navigation-entry-interface) object that you pass to the [navigate](#navigate) method to `true`.
63
65
64
66
```ts
65
67
frame.navigate({
66
-
moduleName: "details/details-page",
67
-
clearHistory: true
68
+
moduleName: 'details/details-page',
69
+
clearHistory: true,
68
70
})
69
71
```
72
+
70
73
### Passing data between pages
71
74
72
75
To pass data to the page you are navigating to, set the value of the [context](#context) property of the NavigationEntry to the data you would like to pass.
76
+
73
77
```ts
74
78
frame.navigate({
75
-
moduleName: "details/details-page",
76
-
context: { id: 2 }
79
+
moduleName: 'details/details-page',
80
+
context: { id: 2 },
77
81
})
78
82
```
79
83
80
84
To access the passed data, handle the `navigatedTo` event for the `details/details-page` page and access the `context` property on the event's [NavigatedData](https://docs.nativescript.org/api-reference/interfaces/navigateddata) object.
81
85
82
86
```ts
83
-
import { NavigatedData } from"@nativescript/core"
87
+
import { NavigatedData } from'@nativescript/core'
84
88
85
-
onNavigatedTo(args: NavigatedData) {
86
-
this.id=args.context.id
87
-
this.notifyPropertyChange("id", args.context.id)
88
-
}
89
+
exportfunctiononNavigatedTo(args:NavigatedData) {
90
+
this.id=args.context.id
91
+
this.notifyPropertyChange('id', args.context.id)
92
+
}
89
93
```
94
+
90
95
### Creating multiple frames
91
96
92
97
If you need to create multiple frames, you can do so by wrapping them in a container layout. For example if you want to have 2 frames side-by-side, you can wrap them in a GridLayout:
@@ -97,260 +102,10 @@ If you need to create multiple frames, you can do so by wrapping them in a conta
97
102
<Framecol="1" />
98
103
</GridLayout>
99
104
```
100
-
## Frame class API
101
-
102
-
The following are the properties and methods of the Frame class:
103
-
104
-
### defaultAnimatedNavigation
105
-
106
-
```ts
107
-
Frame.defaultAnimatedNavigation=true
108
-
```
109
-
110
-
Gets or sets if navigation transitions should be animated globally.
Gets or sets the default [NavigationTransition](#navigation-transition-interface) for all frames across the app. To set a naviagation transtion for a specific frame instance, use the [transition](#transition) property.
Gets the back stack for a Frame instance. It is empty if the current page is the app's initial page(eg `main-page`) or if the [clearHistory](#clearhistory) property is set to `true`.
134
-
135
-
---
136
-
### currentPage
137
-
```ts
138
-
const page:Page=frame.currentPage
139
-
```
140
-
Gets the Page instance the Frame is currently navigated to.
The Navigation Transition interface has the following members:
229
-
230
-
### name
231
-
```ts
232
-
{
233
-
name: "slideLeft"
234
-
}
235
-
```
236
-
The type of the transition. Possible values:
237
-
238
-
-`curl` (same as curlUp) (iOS only)
239
-
-`curlUp` (iOS only)
240
-
-`curlDown` (iOS only)
241
-
-`explode` (Android Lollipop(21) and up only)
242
-
-`fade`
243
-
-`flip` (same as flipRight)
244
-
-`flipRight`
245
-
-`flipLeft`
246
-
-`slide` (same as slideLeft)
247
-
-`slideLeft`
248
-
-`slideRight`
249
-
-`slideTop`
250
-
-`slideBottom`
251
-
---
252
-
253
-
### custom transition
254
-
```ts
255
-
{
256
-
instance: customTransitionInstance
257
-
}
258
-
```
259
-
This property allows you to define custom transition instance of the [Transition](https://docs.nativescript.org/api-reference/classes/transition) class.
260
-
261
-
---
262
-
263
-
### duration
264
-
```ts
265
-
{
266
-
duration: 500
267
-
}
268
-
```
269
-
The length of the transition in milliseconds
270
-
271
-
---
272
-
### curve
273
-
```ts
274
-
import { CoreTypes } from"@nativescript/core";
275
-
276
-
{
277
-
curve: CoreTypes.AnimationCurve.easeInOut,
278
-
}
279
-
```
280
-
A transition animation curve with available values contained in the [AnimationCurve enumeration](https://docs.nativescript.org/api-reference/modules/coretypes.animationcurve).
281
-
Alternatively, you can pass an instance of type [UIViewAnimationCurve](https://developer.apple.com/documentation/uikit/uiview/animationcurve) for iOS or [android.animation.TimeInterpolator](https://developer.android.com/reference/android/animation/TimeInterpolator) for Android.
282
-
283
-
---
284
-
285
-
## Navigation Entry Interface
286
-
287
-
### moduleName
288
-
```ts
289
-
{
290
-
moduleName: "details/details-page"
291
-
}
292
-
```
293
-
The name of the page (a View instance) to navigate to.
294
-
295
-
---
296
-
### create()
297
-
```ts
298
-
{
299
-
create() {
300
-
const page =newPage()
301
-
const actionBar =newActionBar()
302
-
actionBar.title="Test heading"
303
-
304
-
const stack =newStackLayout()
305
-
stack.backgroundColor="#76ABEB"
306
-
307
-
page.actionBar=actionBar;
308
-
page.content=stack
309
-
returnpage
310
-
},
311
-
}
312
-
```
313
-
Creates a the page(View instance) to be navigated to
314
-
315
-
---
316
-
### context
317
-
```ts
318
-
{
319
-
context: any
320
-
}
321
-
```
322
-
An object used to pass data to the page navigated to.
323
-
324
-
---
325
-
326
-
### transitionAndroid
327
-
328
-
_Optional_: Specifies a navigation transition for Android. This property has a higher priority than the [transition](#transition) property.
329
-
330
-
---
331
-
### transitioniOS
332
-
333
-
_Optional_: Specifies a navigation transition for iOS. This property has a higher priority than the [transition](#transition) property.
334
-
335
-
---
336
-
### backstackVisible
337
-
```ts
338
-
frame.backstackVisible=true
339
-
```
340
-
341
-
A boolean value, if set to `true`, it records the navigation in the backstack. If set to `false`, the Page will be displayed but once navigated from it is not possible to navigate back.
342
-
343
-
---
344
-
### clearHistory
345
-
```ts
346
-
{
347
-
clearHistory: true
348
-
}
349
-
```
350
-
If set to `true`, it clears the navigation history. This very useful when navigating away from a login page.
106
+
## See also
351
107
352
-
## API Reference(s)
353
-
-[Frame](https://docs.nativescript.org/api-reference/classes/frame) class
0 commit comments