7.1.0 • Published 2 years ago

react-native-enroute v7.1.0

Weekly downloads
1
License
WTFPL
Repository
github
Last release
2 years ago

React Native Enroute

Simple and fast React Native router based on react-enroute and native navigation

NPM version

To be honest it is not real router at all. This package contains some wrappers for using react-enroute with react-native-screens. Library plays well with Redux and MobX.

Usage

yarn add react-native-enroute react-enroute react-native-screens @react-navigation/native
import {Router} from 'react-enroute'
import {State, createStack} from 'react-native-enroute'


function Routes({
  location,
  paths,
  onNavigateBack,
}) {
  const ShopTab = createStack({paths, onNavigateBack})
  const QuestTab = createStack({paths, onNavigateBack})

  return (
    <Router {...{location}}>
      <ShopTab path='/shops'>
        <ShopList/>
        <Shop path=':id'/>
      </ShopTab>
      <QuestTab path='/quest'>
        <AllQuestions/>
        <Question path=':id'/>
      </QuestTab>
    </Router>
  )
}

function App() {
  const routerState = useMemo(() => new State('/shops'), [])
  const pop = useCallback(() => {
    routerState.pop()
    return true
  }, [])
  
  const openShop123 = useCallback(() => {
    routerState.push('/shops/123')
  }, [])
  const resetToQuest1 = useCallback(() => {
    routerState.reset('/quest/1')
  }, []) 

  useEffect(() => {
    BackHandler.addEventListener('hardwareBackPress', pop)

    return () => {
      BackHandler.removeEventListener('hardwareBackPress', pop)
    }
  }, [])

  return (
    <View>
      <Button onPress={openShop123}/>
      <Button onPress={resetToQuest1}/>
      <Routes
        location={routerState.current}
        paths={routerState.paths}
        onNavigateBack={pop}
      />
    </View>
  )
}
7.1.0

2 years ago

7.0.0

3 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.0.0

4 years ago

4.0.0

5 years ago

3.0.0

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

7 years ago