router-react-native
v1.0.8
Published
Routing + Navigation Bar + Left Panel for react native apps
Downloads
4
Maintainers
Readme
Install
npm i router-react-native
Usage
import Router from 'router-react-native';
export default class MyApp extends Component {
render() {
return (
<Router
routes={[
{ index: Index },
{ login: Login },
{ users: Users },
...
{ defaultRouteName: DefaultRouteComponent }
]}
defaultRoute='defaultRouteName'
initialRoute='index'
navBar={<NavBarComponent />}
leftPanel={<LeftPanelComponent />}
onOpen={() => { alert('Left panel opened!') }}
onClose={() => { alert('Left panel closed!') }}
leftPanelOffset={100}
/>
);
}
}
AppRegistry.registerComponent('MyApp', () => MyApp);
Change routes
import { pushRoute, popRoute } from 'router-react-native';
handleNextClick() {
const hideNavBar = true;
const routeParameters = { ... };
...
pushRoute('routeName', routeParameters, hideNavBar);
}
handleBackClick() {
popRoute();
}
Props
routes
: An array to map route ids with route's componentinitialRoute
: id of the initial routedefaultRoute
: id of the default route (in case no matching route id is found)navBar
: Component which will be rendered as the top navigation barleftPanel
: Component which will be rendered as the left panelonOpen
: Event handler for left panel openonClose
: Event handler for left panel closeleftPanelOffset
: Space to be left empty while opening left panel (default100
)
Exports
currentRoute
: Information about the current routecurrentRoute.id
: Unique route idcurrentRoute.params
: Route parameterscurrentRoute.index
: Index in the routing stack
pushRoute (id, params, hideNavBar)
: To go to a new routeid
: The route's idparams
: Optional routing parametershideNavBar
:true
for hiding the navigation bar for this new route
popRoute (n)
: Go backn
routes (1
by default).0
to clear history, and go to initial routeupdateLayoutData (Object)
: Update thelayoutData
prop of navBar/leftPanel components
Props for navBar
& leftPanel
toggleLeftPanel()
: Toggle left panelshowingLeftPanel
: Whether left panel is visible or not (true/false
)layoutData
: Any data which needs to be sent to the layout components (navBar/leftPanel)
router-react-native NPM module