-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native Quick Start, Link Documentation, and Examples #4678
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# <Prompt> | ||
|
||
TODO | ||
Re-exported from core [`Prompt`](../../../react-router/docs/api/Prompt.md) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,49 @@ | ||
# <Link> | ||
|
||
TODO | ||
Provide declarative, accessible navigation around your application. | ||
|
||
```js | ||
import { Link } from 'react-router-native' | ||
|
||
<Link to='/about'>About</Link> | ||
``` | ||
|
||
## to: string | ||
|
||
The pathname or location to link to. | ||
|
||
```js | ||
<Link to='/courses'/> | ||
``` | ||
|
||
## to: object | ||
|
||
The location to link to. | ||
|
||
```js | ||
<Link to={{ | ||
pathname: '/courses', | ||
search: '?sort=name', | ||
hash: '#the-hash', | ||
state: { fromDashboard: true } | ||
}}/> | ||
``` | ||
|
||
## replace: bool | ||
|
||
When `true`, clicking the link will replace the current entry in the history stack instead of adding a new one. | ||
|
||
```js | ||
<Link to="/courses" replace /> | ||
``` | ||
|
||
## component: func | ||
|
||
A component for making `Link` respond properly to touches. Typically will be one React Native's "touchable" components (`TouchableHighlight`, `TouchableOpacity`, etc). All props passed to `Link` will be passed along to this component. Defaults to `TouchableHighlight`. | ||
|
||
```js | ||
<Link | ||
to='/about' | ||
component={TouchableOpacity} | ||
activeOpacity={0.8} /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# <Prompt> | ||
|
||
Re-exported from core [`Prompt`](../../../react-router/docs/api/Prompt.md) |
131 changes: 125 additions & 6 deletions
131
packages/react-router-native/docs/guides/quick-start.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,137 @@ | ||
# Quick Start | ||
|
||
Gimme 10 minutes, you'll be up and running. | ||
|
||
## Exponent | ||
|
||
Easiest way to get started is probably with Exponent. | ||
If this is your first time building a React Native app, we recommend you check out the official ["Getting Started"](https://facebook.github.io/react-native/docs/getting-started.html) guide. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
## Installation | ||
|
||
React Router Native is published to [npm](https://npm.im/react-router-native) so you can install it with either `npm` or [`yarn`](https://yarnpkg.com). | ||
React Router Native is published to [npm](https://npm.im/react-router-native). You can install it with either `npm` or [`yarn`](https://yarnpkg.com). | ||
|
||
```sh | ||
npm install react-router-native@next | ||
# or | ||
yarn add react-router-native@next | ||
``` | ||
|
||
Once you've initialized a new React Native project, you can copy/paste any of the examples into your `index.ios.js` or `index.android.js` files to play around with them. | ||
|
||
Here's the basic example: | ||
|
||
```jsx | ||
import React from 'react' | ||
import { | ||
StyleSheet, | ||
Text, | ||
View, | ||
AppRegistry, | ||
} from 'react-native' | ||
|
||
import { NativeRouter, Route, Link } from 'react-router-native' | ||
|
||
const Home = () => ( | ||
<Text style={styles.header}> | ||
Home | ||
</Text> | ||
) | ||
|
||
const About = () => ( | ||
<Text style={styles.header}> | ||
About | ||
</Text> | ||
) | ||
|
||
const Topic = ({ match }) => ( | ||
<Text style={styles.topic}> | ||
{match.params.topicId} | ||
</Text> | ||
) | ||
|
||
const Topics = ({ match }) => ( | ||
<View> | ||
<Text style={styles.header}>Topics</Text> | ||
<View> | ||
<Link | ||
to={`${match.url}/rendering`} | ||
style={styles.subNavItem} | ||
underlayColor='#f0f4f7'> | ||
<Text>Rendering with React</Text> | ||
</Link> | ||
<Link | ||
to={`${match.url}/components`} | ||
style={styles.subNavItem} | ||
underlayColor='#f0f4f7'> | ||
<Text>Components</Text> | ||
</Link> | ||
<Link | ||
to={`${match.url}/props-v-state`} | ||
style={styles.subNavItem} | ||
underlayColor='#f0f4f7'> | ||
<Text>Props v. State</Text> | ||
</Link> | ||
</View> | ||
|
||
<Route path={`${match.url}/:topicId`} component={Topic}/> | ||
<Route exact path={match.url} render={() => ( | ||
<Text style={styles.topic}>Please select a topic.</Text> | ||
)} /> | ||
</View> | ||
) | ||
|
||
const nativeRouterExamples = () => ( | ||
<NativeRouter> | ||
<View style={styles.container}> | ||
<View style={styles.nav}> | ||
<Link | ||
to="/" | ||
underlayColor='#f0f4f7' | ||
style={styles.navItem}> | ||
<Text>Home</Text> | ||
</Link> | ||
<Link | ||
to="/about" | ||
underlayColor='#f0f4f7' | ||
style={styles.navItem}> | ||
<Text>About</Text> | ||
</Link> | ||
<Link | ||
to="/topics" | ||
underlayColor='#f0f4f7' | ||
style={styles.navItem} > | ||
<Text>Topics</Text> | ||
</Link> | ||
</View> | ||
|
||
<Route exact path="/" component={Home}/> | ||
<Route path="/about" component={About}/> | ||
<Route path="/topics" component={Topics}/> | ||
</View> | ||
</NativeRouter> | ||
) | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginTop: 25, | ||
padding: 10, | ||
}, | ||
header: { | ||
fontSize: 20, | ||
}, | ||
nav: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-around' | ||
}, | ||
navItem: { | ||
flex: 1, | ||
alignItems: 'center', | ||
padding: 10, | ||
}, | ||
subNavItem: { | ||
padding: 5, | ||
}, | ||
topic: { | ||
textAlign: 'center', | ||
fontSize: 15, | ||
} | ||
}) | ||
|
||
AppRegistry.registerComponent('MyApp', () => App); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react' | ||
import { StyleSheet, Text, AppRegistry, View } from 'react-native' | ||
import { NativeRouter, Route, Link, Switch } from 'react-router-native' | ||
|
||
const About = () => <Text style={styles.header}>About</Text> | ||
const Company = () => <Text style={styles.header}>Company</Text> | ||
const User = ({ match }) => ( | ||
<Text style={styles.header}>User: {match.params.user}</Text> | ||
) | ||
|
||
const AmbiguousExample = () => ( | ||
<NativeRouter> | ||
<View style={styles.container}> | ||
<View> | ||
<Link to="/about" underlayColor='#f0f4f7'> | ||
<Text>About Us (static)</Text> | ||
</Link> | ||
<Link to="/company" underlayColor='#f0f4f7'> | ||
<Text>Company (static)</Text> | ||
</Link> | ||
<Link to="/kim" underlayColor='#f0f4f7'> | ||
<Text>Kim (dynamic)</Text> | ||
</Link> | ||
<Link to="/chris" underlayColor='#f0f4f7'> | ||
<Text>Chris (dynamic)</Text> | ||
</Link> | ||
</View> | ||
|
||
{/* | ||
Sometimes you want to have a whitelist of static paths | ||
like "/about" and "/company" but also allow for dynamic | ||
patterns like "/:user". The problem is that "/about" | ||
is ambiguous and will match both "/about" and "/:user". | ||
Most routers have an algorithm to decide for you what | ||
it will match since they only allow you to match one | ||
"route". React Router lets you match in multiple places | ||
on purpose (sidebars, breadcrumbs, etc). So, when you | ||
want to clear up any ambiguous matching, and not match | ||
"/about" to "/:user", just wrap your <Route>s in a | ||
<Switch>. It will render the first one that matches. | ||
*/} | ||
<Switch> | ||
<Route path="/about" component={About}/> | ||
<Route path="/company" component={Company}/> | ||
<Route path="/:user" component={User}/> | ||
</Switch> | ||
</View> | ||
</NativeRouter> | ||
) | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
marginTop: 25, | ||
padding: 10, | ||
}, | ||
header: { | ||
fontSize: 20, | ||
}, | ||
}) | ||
|
||
export default AmbiguousExample |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanflorence Can you confirm this is right? It's how all the other files were but it wasn't importing correctly for me. I'm assuming there's some build step I wasn't running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is correct.
react-router-native
re-exports everything from corehttps://github.com/ReactTraining/react-router/blob/a757d7f2c56bfbc54833a82620a67f8ddf83e7e7/packages/react-router-native/main.js#L1