-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Closed
Description
Hello,
I try to use history push anywhere in the code, so
my render method is just:
myhistory.js
class MyHistory {
history;
constructor() {
this.history = createMemoryHistory({
initialEntries: ['/'], // The initial URLs in the history stack
initialIndex: 0, // The starting index in the history stack
keyLength: 10, // The length of location.key
// A function to use to confirm navigation with the user. Required
// if you return string prompts from transition hooks (see below)
getUserConfirmation: null,
});
}
}
export default new MyHistory;
// all of my import ..
import { MemoryRouter, Route, Switch } from 'react-router-native';
import MyHistory from './myhistory';
class MyApp extends React.Component {
render() {
return (
<MemoryRouter history={MyHistory.history}>
<Switch>
<Route exact path="/" component={MainScene} />
<Route path="/user" component={UserScene} />
<Route path="/test" component={TestScene} />
</Switch>
</MemoryRouter>
);
}
}
AppRegistry.registerComponent('MyApp', () => MyApp);
In other parts of my code I tried to call like this:
import MyHistory from './myhistory';
MyHistory.history.push('/user');
I don't know if it is a bug in react native or me
Metadata
Metadata
Assignees
Labels
No labels