|
| 1 | +# Installation {id=installation} |
| 2 | + |
| 3 | +React Router runs in multiple environments: browsers, servers, native, and even VR (works in the dev preview!) While many components are shared (like `Route`) others are specific to environment (like `NativeRouter`). Rather than requiring you install two packages, you only have to install the package for the target environment. Any shared components between the environments are re-exported from the environment specific package. |
| 4 | + |
| 5 | +## Web {id=installationweb} |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install react-router-dom@next` |
| 9 | +# or |
| 10 | +yarn add react-router-dom@next |
| 11 | +``` |
| 12 | + |
| 13 | +All of the package modules can be imported from the top: |
| 14 | + |
| 15 | +```js |
| 16 | +import { |
| 17 | + BrowserRouter as Router |
| 18 | + StaticRouter // for server rendering |
| 19 | + Route, |
| 20 | + Link |
| 21 | + // etc. |
| 22 | +} from 'reat-router-dom' |
| 23 | +``` |
| 24 | + |
| 25 | +If you're going for a really minimal bundle sizes on the web you can import modules directly. Theoretically a tree-shaking bundler like Webpack makes this unnecessary but we haven't tested it yet. We welcome you to! |
| 26 | + |
| 27 | +```js |
| 28 | +import Router from 'react-router-dom/BrowserRouter' |
| 29 | +import Route from 'react-router/Router' |
| 30 | +// etc. |
| 31 | +``` |
| 32 | + |
| 33 | +## Native {id=installation.native} |
| 34 | + |
| 35 | +We're still working on great documentation for the native capabilities of React Router. For now we recommend you [read the source](https://github.com/ReactTraining/react-router/tree/v4/packages/react-router-native). |
| 36 | +
|
| 37 | +```bash |
| 38 | +yarn add react-router-native@next |
| 39 | +# or if not using the react-native cli |
| 40 | +npm install react-router-native@next |
| 41 | +``` |
| 42 | +
|
| 43 | +All of the package modules can be imported from the top: |
| 44 | +
|
| 45 | +```js |
| 46 | +import { |
| 47 | + NativeRouter as Router |
| 48 | + DeepLinking, |
| 49 | + AndroidBackButton, |
| 50 | + Link, |
| 51 | + Route |
| 52 | + // etc. |
| 53 | +} from 'react-router-native' |
| 54 | +``` |
| 55 | +
|
| 56 | +## Who-knows-where {id=installation.who-knows-where} |
| 57 | +
|
| 58 | +```bash |
| 59 | +yarn add react-router@next |
| 60 | +# or if not using the react-native cli |
| 61 | +npm install react-router@next |
| 62 | +``` |
| 63 | +
|
| 64 | +All of the package modules can be imported from the top: |
| 65 | +
|
| 66 | +```js |
| 67 | +import { |
| 68 | + MemoryRouter as Router, |
| 69 | + Route |
| 70 | + // etc. |
| 71 | +} from 'reat-router' |
| 72 | +``` |
| 73 | +
|
| 74 | +You can use React Router's navigation anywhere you run React, the navigation state is kept in a memory router. You can look at the implementation of NativeRouter to get an idea on how to integrate. |
0 commit comments