-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: use navigate without hook #8481
Comments
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
There is a new API for this: import { createBrowserHistory } from 'history';
import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
let history = createBrowserHistory();
function App() {
return (
<HistoryRouter history={history}>
// The rest of your app
</HistoryRouter>
);
}
history.push("/foo"); Use that |
The problem with the proposed solution is when your app is served with a non-empty basename. Because basename handling has been moved from history (up to Router), you need prepend the basename when using the history instance directly, while you don't when using |
Your proposed solution doesn't work in redux store as route changes but components doesn't re render APP.js import { let history = createBrowserHistory(); function App() { export default App; Redux Store actions export const Login = (data) => (dispatch) => { }) Issue |
Kindly solve this issue as i don't want to downgrade to V5 as i have implemented react-router V^ in most of the product |
@Kamran95 You're creating 2 history instances of history in the snippets you posted. You're supposed to create only one and use it in your app when you need it. |
can you please provide example please |
import "./App.css"; import Routes from "./Routes/router"; let history = createBrowserHistory(); function App() { export default App; this also doesn't work just for testinng |
and you cannot use BrowserRouter while using HistoryRouter |
What I mean is that you create a single history instance in a module and you import that module elsewhere in your app when you need to access the history. History.js
App.js
Redux store
|
I found a solution is below, don't need install History.js
NavigateSetter.js
App.js
AnyFiles.js
|
Looks like there's out-of-the-box solution: https://reactrouter.com/en/main/fetch/redirect |
This doesn't work all of the time unfortunately, came here exactly because it doesn't work for this use-case, I believe its for the new data-router. |
What is the new or updated feature that you are suggesting?
a static navigate function that can be used without hook, like:
Why should this feature be included?
I have a
api.js
file, it's not React Component, I want to navigate to login page when api(need login) request failed.The text was updated successfully, but these errors were encountered: