Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPassing custom browser history into IonReactRouter #20297
Comments
|
I agree with you, and I am interested in a solution for that. FYI, I had recently put a bounty on an old question on Stackoverflow that you might wanna check https://stackoverflow.com/questions/55884643/ionic-4-routing-with-angular-6 Basically the situation, as I understand it, is the following:
|
|
Another concrete use case: user needs to listen for the
To my knowledge there's not a clean way to handle this. |
|
IonReactRouter currently wraps BrowserRouter, which doesn't accept pre-built history. I'll look into changing it to wrap Router instead and provide the browser stuff ourselfs. |
|
When we can apply a custom browser history to the IonReactRouter component? |
|
In case anyone finds this issue and is disappointed this hasn't been implemented yet, here's a quick workaround which seems to work for us. import React from 'react'
import { History } from 'history'
import { useHistory } from 'react-router'
// Add custom property 'appHistory' to the global window object
declare global {
interface Window { appHistory: History }
}
const MyApp: React.FC = () => {
// Store the history object globally so we can access it outside of React components
window.appHistory = useHistory()
...
}You are now able to access and mutate the history from anywhere in your app using the |
|
Hi @elylucas, are there any updates on this? |
Ionic version:
[x] 4.x
[ ] 5.x
I'm submitting a ...
[ ] bug report
[x] feature request
Current behavior:
IonReactRouterdoesn't give you the option to pass in a custom browser history. It would be great if you could do so like you can if you use theRoutercomponent fromreact-router-dom(https://reacttraining.com/react-router/web/api/Router)Expected behavior:
To be able to use custom history like so