Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit 102e2c0

Browse files
committed
Merge pull request #13 from NativeScript/navigation
Updated navigation article.
2 parents 83c972c + 9982dab commit 102e2c0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

navigation.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var navigationEntry = {
125125
topmost.navigate(navigationEntry);
126126
```
127127
#Navigating to another page and passing context
128-
Sometimes, the page being navigated to would have to receive information about the context in which this navigation happened. The bese example would be a master-details scenario where there are two pages -- the main page containing a list of some entities and a details page which provides details about a particular entity. In this case, when navigating to the details page it is mandatory to transfer some primary key or ID information about the entity the details page should show. This is done with the help of the **context** property of a NavigationEntry:
128+
Sometimes, the page being navigated to would have to receive information about the context in which this navigation happened. The best example would be a master-details scenario where there are two pages -- the main page containing a list of some entities and a details page which provides details about a particular entity. In this case, when navigating to the details page it is mandatory to transfer some primary key or ID information about the entity the details page should show. This is done with the help of the **context** property of a NavigationEntry:
129129
``` JavaScript
130130
function listViewItemTap(args) {
131131
frames.topmost().navigate({
@@ -143,6 +143,21 @@ export function listViewItemTap(args: listView.ItemEventData) {
143143
});
144144
}
145145
```
146+
Once you pass this information, the best place to retrieve it and act accordingly is in the **onNavigatedTo** callback of the details page:
147+
``` JavaScript
148+
function pageNavigatedTo(args) {
149+
var page = args.object;
150+
page.bindingContext = page.navigationContext;
151+
}
152+
```
153+
``` TypeScript
154+
// Event handler for Page "navigatedTo" event attached in details-page.xml
155+
export function pageNavigatedTo(args: observable.EventData) {
156+
// Get the event sender
157+
var page = <pages.Page>args.object;
158+
page.bindingContext = page.navigationContext;
159+
}
160+
```
146161
#Navigating Back
147162
The topmost frame keeps track of the pages the user has visited in a navigation stack. To go back to a previous page you should use the **goBackMethod** of the topmost frame instance:
148163
``` JavaScript
@@ -152,5 +167,4 @@ topmost.goBack();
152167
topmost.goBack();
153168
```
154169
#Alternatives
155-
Alternatively, if you do not want to have different pages and navigate beteen them, you can have a single page with a TabView. You can define a different UI for each tab and when the user selects a certain tab he will be presented with this UI.
156-
170+
Alternatively, if you do not want to have different pages and navigate beteen them, you can have a single page with a TabView. You can define a different UI for each tab and when the user selects a certain tab he will be presented with this UI.

0 commit comments

Comments
 (0)