Skip to content

Commit 410ff11

Browse files
Jack Harrisaksonov
Jack Harris
authored andcommitted
Documentation for Deep Linking (aksonov#2615)
* adding to api * Update API.md * Update API.md * allows export for path parse * Update API.md
1 parent 70be678 commit 410ff11

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/API.md

+22
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
| `wrapBy`   | `Function` | | function to wrap each Scene component and nav bar buttons - allows easy MobX integration (by passing `observer`) |
2020
| `sceneStyle` | `Style` | | Style applied to all scenes (optional) |
2121
| `backAndroidHandler` | `Function` | | Allows custom control of hardwareBackPress in Android (optional). For more info check [BackHandler](https://facebook.github.io/react-native/docs/backhandler.html). |
22+
| `uriPrefix` | `string` | | A uri prefix to strip from incoming urls for deep linking. For example, if you wanted to support deep linking from `www.example.com/user/1234/`, then you could pass `example.com` to only match paths against `/user/1234/`. |
2223

2324
## Scene:
2425
The basic routing component for this router, all `<Scene>` components require a `key` prop that must be unique. A parent `<Scene>` cannot not have a `component` as a `prop` as it will act as a grouping component for its children.
2526

2627
| Property | Type | Default | Description |
2728
|-----------|----------|----------|--------------------------------------------|
2829
| `key`       | `string` | `required` | Will be used to call screen transition, for example, `Actions.name(params)`. Must be unique. |
30+
| `path`       | `string` | | Will be used to match against incoming deep links and pull params. For example, the path `/user/:id/` would specify to call the Scene's action with params `{ id: 1234 }` from the url `/user/1234/`. Should adhere to widely accepted uri templating standard https://tools.ietf.org/html/rfc6570 |
2931
| `component` | `React.Component` | `semi-required` | The `Component` to be displayed. Not required when defining a nested `Scene`, see example. |
3032
| `back`     | `boolean` | `false` | If it is `true` back button is displayed instead of left/drawer button defined by upper container. |
3133
| `backButtonImage` | `string` | | Image source to substitute for the nav back button |
@@ -193,3 +195,23 @@ Type constants to determine `Scene` transitions, These are **PREFERRED** over ty
193195
| `ActionConst.FOCUS` | `string` | 'REACT_NATIVE_ROUTER_FLUX_FOCUS' | *N/A* |
194196
| `ActionConst.BLUR` | `string` | 'REACT_NATIVE_ROUTER_FLUX_BLUR' | *N/A* |
195197
| `ActionConst.ANDROID_BACK` | `string` | 'REACT_NATIVE_ROUTER_FLUX_ANDROID_BACK' | *N/A* |
198+
199+
## Universal and Deep Linking
200+
#### Use Case
201+
- Consider a web app and mobile app pairing for a social network, which might have a url `https://thesocialnetwork.com/profile/1234/`.
202+
- If we were building both a web app and a mobile app, we'd like to be able to express that uri scheme across platforms with the path `/profile/:id/`.
203+
- On the web, we might want `React-Router` to to open up our `<Profile />` component with the `props` `{ id: 1234 }`.
204+
- On mobile, if we've correctly set up our Android/iOS environment to launch our application and open our RNRF `<Router />`, then we also want to navigate to our mobile `<Profile />` scene with the `params` ` { id: 1234 }`
205+
206+
#### Usage
207+
```javascript
208+
<Router uriPrefix={'thesocialnetwork.com'}>
209+
<Scene key="root">
210+
<Scene key={'home'} component={Home} />
211+
<Scene key={'profile'} path={"/profile/:id/"} component={Profile} />
212+
<Scene key={'profileForm'} path={"/edit/profile/:id/"} component={ProfileForm} />
213+
</Scene>
214+
</Router>
215+
```
216+
217+
If a user clicks on `http://thesocialnetwork.com/profile/1234/` on their device, they'll open the `<Router />` and then call `Actions.profile({ id: 1234 })`

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Stack from './Stack';
99
import Drawer from './Drawer';
1010
import Tabs from './Tabs';
1111
import Overlay from './Overlay';
12+
import pathParser from './pathParser';
1213

1314
export {
1415
ActionConst,
@@ -22,4 +23,5 @@ export {
2223
Drawer,
2324
Tabs,
2425
Overlay,
26+
pathParser,
2527
};

0 commit comments

Comments
 (0)