{"id":3996,"url":"https://github.com/jmurzy/react-router-native","last_synced_at":"2025-04-05T15:05:43.485Z","repository":{"id":82771173,"uuid":"55477760","full_name":"jmurzy/react-router-native","owner":"jmurzy","description":"A routing library for React Native that strives for sensible API parity with react-router 🤖","archived":false,"fork":false,"pushed_at":"2020-02-13T09:27:13.000Z","size":1333,"stargazers_count":638,"open_issues_count":38,"forks_count":44,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-03-29T14:06:49.168Z","etag":null,"topics":["react-native","react-router"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmurzy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-04-05T07:35:40.000Z","updated_at":"2025-03-16T15:36:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"71c4a4f7-76ff-40f3-ba41-5d9ca2bf5765","html_url":"https://github.com/jmurzy/react-router-native","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmurzy%2Freact-router-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmurzy%2Freact-router-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmurzy%2Freact-router-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmurzy%2Freact-router-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmurzy","download_url":"https://codeload.github.com/jmurzy/react-router-native/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353731,"owners_count":20925329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["react-native","react-router"],"created_at":"2024-01-05T20:16:57.985Z","updated_at":"2025-04-05T15:05:43.462Z","avatar_url":"https://github.com/jmurzy.png","language":"JavaScript","readme":"# React Router Native [![CircleCI](https://img.shields.io/circleci/project/jmurzy/react-router-native/master.svg?style=flat-square)](https://circleci.com/gh/jmurzy/react-router-native) [![npm version](https://img.shields.io/npm/v/react-router-native.svg?style=flat-square)](https://www.npmjs.com/package/react-router-native) [![npm](https://img.shields.io/npm/l/react-router-native.svg?style=flat-square)](https://github.com/jmurzy/react-router-native/blob/master/LICENSE.md) [![Discord Channel](https://img.shields.io/badge/discord-react--router@reactiflux-738bd7.svg?style=flat-square)](https://discord.gg/0ZcbPKXt5bYaNQ46) [![Medium](https://img.shields.io/badge/blog-medium-brightgreen.svg)](https://commitocracy.com/introducing-react-router-native-b02e76b8ca5d)\n\nA routing library for [React Native](https://github.com/facebook/react-native) that strives for sensible API parity with [react-router](https://github.com/reactjs/react-router/).\n\n```\nPlease note that React Router v4 was just released. Over the next few weeks,\nReact Router Native will be refactored to make it fully compatible with v4.\n```\n\n\u003cimg align=\"right\" width=\"360px\" src=\"https://raw.githubusercontent.com/jmurzy/react-router-native/master/docs/screenshot.gif\"\u003e\n\n### Background\n\nReact Router community decided that a [reducer-based paradigm](https://github.com/reactjs/react-router/issues/743) similar to that of **NavigationExperimental** is better suited to native navigation. Transition to a reducer-based paradigm is also being [discussed](https://github.com/reactjs/react-router/issues/3190) for the web. On the other hand, NavigationExperimental [has no intention to support ](https://github.com/ericvicenti/navigation-rfc/issues/64#issuecomment-209001717) a React Router-like interface and leaves the navigation state up to the developer to maintain.\n\nA declarative API removes the need to write [boilerplate code](https://github.com/facebook/react-native/commit/1dc33b5f23640a60682ac879b9a3e94a4aa519d9) and speeds up development. React Router Native follows React's __Learn Once, Write Anywhere__ principle by providing a superset of React Router's API that marries _React Router_ to _NavigationExperimental_.\n\n#### Goals\n\n- URL Driven Development\n- Learn once, write anywhere: knowledge and proven idioms from react-router can be reused while extending them as necessary to allow navigation semantics unique to native platforms\n- First class deep linking support\n- [Cross-platform](#platform-support)\n\n**Note**: This project contains components that are currently under [active](https://github.com/facebook/react-native/commits?author=ericvicenti) [development](https://github.com/facebook/react-native/commits?author=hedgerwang) and considered experimental—aka use in production at your own risk.\n\n### Installation\n\n#### Using npm:\n\n```sh\n$ npm install --save react-router-native\n```\n\n#### Using yarn:\n\n```sh\n$ yarn add react-router-native\n```\n\n### Usage\n\n```javascript\n/**\n * index.[ios|android].js\n */\n\nimport React from 'react';\nimport {\n  Header,\n  Link,\n  nativeHistory,\n  Route,\n  Router,\n  StackRoute,\n  withRouter,\n} from 'react-router-native';\nimport {\n  AppRegistry,\n  ScrollView,\n  StyleSheet,\n  View,\n} from 'react-native';\n\nconst styles = StyleSheet.create({\n  component: {\n    backgroundColor: '#FFFFFF',\n    flex: 1,\n  },\n  home: {\n    backgroundColor: '#FFFFFF',\n    flexDirection: 'row',\n    flexWrap: 'wrap',\n    justifyContent: 'center',\n  },\n  detailCard: {\n    height: 100,\n    margin: 20,\n    width: 100,\n  },\n});\n\nconst Master = (props) =\u003e (\n  \u003cView style={styles.component}\u003e\n    {props.children}\n  \u003c/View\u003e\n);\n\nconst HomeHeader = withRouter((props) =\u003e {\n  const handleRightButtonPress = () =\u003e {\n    props.router.push('/detail/gray');\n  };\n\n  return (\n    \u003cHeader\n      {...props}\n      style={{ backgroundColor: '#26BBE5' }}\n      title=\"Feed\"\n      rightButtonText=\"Gray\"\n      onRightButtonPress={handleRightButtonPress}\n    /\u003e\n  );\n});\n\nconst Home = () =\u003e {\n  const DetailCard = ({ backgroundColor }) =\u003e (\n    \u003cLink to={`/detail/${encodeURIComponent(backgroundColor)}`} style={styles.detailCard}\u003e\n      \u003cView style={{ flex: 1, backgroundColor }} /\u003e\n    \u003c/Link\u003e\n  );\n\n  return (\n    \u003cScrollView style={styles.component} contentContainerStyle={styles.home}\u003e\n      \u003cDetailCard backgroundColor=\"#EF4E5E\" /\u003e\n      \u003cDetailCard backgroundColor=\"#9498CA\" /\u003e\n      \u003cDetailCard backgroundColor=\"#AFCCB3\" /\u003e\n      \u003cDetailCard backgroundColor=\"#F0D73D\" /\u003e\n      \u003cDetailCard backgroundColor=\"#A176B0\" /\u003e\n      \u003cDetailCard backgroundColor=\"#416BB4\" /\u003e\n      \u003cDetailCard backgroundColor=\"#94B5DC\" /\u003e\n      \u003cDetailCard backgroundColor=\"#D48445\" /\u003e\n    \u003c/ScrollView\u003e\n  );\n};\n\nconst DetailHeader = withRouter((props) =\u003e {\n  const { routeParams } = props;\n  const title = routeParams.themeColor;\n  const backgroundColor = routeParams.themeColor;\n  const colors = ['#EF4E5E', '#D48445', '#AFCCB3', '#F0D73D', '#A176B0'];\n\n  const handleRightButtonPress = () =\u003e {\n    const randomIndex = Math.floor(Math.random() * colors.length);\n    const randomColor = colors[randomIndex];\n    props.router.push(`/detail/${encodeURIComponent(randomColor)}`);\n  };\n\n  return (\n    \u003cHeader\n      {...props}\n      title={title}\n      style={{ backgroundColor }}\n      leftButtonText=\"Back\"\n      rightButtonText=\"Random\"\n      onRightButtonPress={handleRightButtonPress}\n    /\u003e\n  );\n});\n\nconst Detail = (props) =\u003e (\n  \u003cView style={[styles.component, { backgroundColor: '#FFFFFF' }]}\u003e{props.children}\u003c/View\u003e\n);\n\nconst routes = (\n  /* Address Bar can be toggled on or off by setting the addressBar prop */\n  \u003cRouter history={nativeHistory} addressBar\u003e\n    \u003cStackRoute path=\"master\" component={Master}\u003e\n      \u003cRoute path=\"/\" component={Home} overlayComponent={HomeHeader} /\u003e\n      \u003cRoute path=\"/detail/:themeColor\" component={Detail} overlayComponent={DetailHeader} /\u003e\n    \u003c/StackRoute\u003e\n  \u003c/Router\u003e\n);\n\nAppRegistry.registerComponent('YourApp', () =\u003e () =\u003e routes);\n```\n\n### Advanced Usage\n\nYou can customize behavior of the default reducers that are used to create the `navigationState` of `\u003cRoute\u003e` or its siblings.\n\nThis allows greater customizations on how `\u003cLink\u003e` behaves for a particular route and is especially useful for nested `\u003cStackRoute\u003e`'s where default action doesn't always lead to the intended behavior, or `\u003cTabsRoute\u003e`'s where double-taps should reset the `navigationState` of a nested `\u003cStackRoute\u003e`.\n\n```js\nconst reducer = (\n  state: EnhancedNavigationState,\n  action: NavigationAction\n): EnhancedNavigationState =\u003e ({\n  /* ... */\n});\n\n\u003cTabsRoute path=\"/\" component={Component} reducer={reducer}/\u003e\n```\n\n### Examples\nThe source includes a few [examples](/examples) that should help you get started. The example app from the GIF above can be found at `examples/Aviato`. You can also [view it with Exponent](https://exp.host/@rncommunity/aviato).\n\nRoute configuration for the example apps can be found in `app/routes.js`. The __address bar__ shown in the demo is used for development only and can be disabled by removing the [`addressBar`](https://github.com/jmurzy/react-router-native/blob/b988ea696cca272296c424e7381df00944c9d062/examples/Aviato/app/routes.js#L23-L24) prop from the ``\u003cRouter\u003e`` component.\n\n### Documentation\nDocumentation can be found [here](/docs).\n\n### Platform Support\n\nReact Router Native is cross-platform. It supports all platforms that [NavigationExperimental](https://github.com/ericvicenti/navigation-rfc) supports.\n\n### Contributing\nWant to hack on React Router Native? Awesome! We welcome contributions from anyone and everyone. Please see our [guidelines](CONTRIBUTING.md) for more information on workflow and setup.\n\n### Questions?\n\nFeel free to reach out to me on Twitter [@jmurzy](https://twitter.com/jmurzy). If you have any questions, please submit an Issue with the \"[question](https://github.com/jmurzy/react-router-native/issues?utf8=%E2%9C%93\u0026q=label%3Aquestion%20)\" tag or come hang out in the React Router [Reactiflux Channel](https://discord.gg/0ZcbPKXt5bYaNQ46) and post your request there.\n\n### Thanks\n\nReact Router Native is based on [React Router](https://github.com/reactjs/react-router). Thanks to Ryan Florence [@ryanflorence](https://twitter.com/ryanflorence), Michael Jackson [@mjackson](https://twitter.com/mjackson) and all the contributors for their work on [react-router](https://github.com/reactjs/react-router) and [history](https://github.com/mjackson/history).\n\nSpecial thanks to Eric Vicenti [@ericvicenti](https://twitter.com/ericvicenti) and Hedger Wang [@hedgerwang](https://twitter.com/hedgerwang) for their work on [NavigationExperimental](https://github.com/ericvicenti/navigation-rfc).\n","funding_links":[],"categories":["Components","JavaScript","Others"],"sub_categories":["UI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmurzy%2Freact-router-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmurzy%2Freact-router-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmurzy%2Freact-router-native/lists"}