当前我的代码正在获取:
[12:35:59] Warning: <MemoryRouter> ignores the history prop. To use a
custom history, use `import { Router }` instead of `import {
MemoryRouter as Router }`.
实际上是NativeRouter,而不是MemoryRouter。
我以为我已经设置了可以在react-native和react-native-web中使用的项目:
import createBrowserHistory from 'history/createBrowserHistory'
import createMemoryHistory from 'history/createMemoryHistory'
import { Platform } from 'react-native'
const customHistory = (() => {
switch (Platform.OS) {
case 'web':
return createBrowserHistory()
case 'ios':
return createMemoryHistory()
default:
console.error(`No such platform configuration ${Platform.OS}`)
}
})()
export default customHistory
然后我称其为
import history from '@src/lib/history'
//...
history.replace('/')
它的安装方式是:
export { NativeRouter as Router, Switch, Route, Link, withRouter } from 'react-router-native'
return (
<ApolloProvider client={this.state.apolloClient}>
<PaperProvider>
<View style={styles.app}>
<Router history={history}>
这在react-native-web ..中工作正常,但是在react-native中,显然有更好的方法吗?