Forge createHistory Api and react-router-dom compatibility

following this tutorial Add routing to a custom UI full page app , when I use useLocation to get the state, the state is always null:

function Link({ to, children }) {
    const navigate = useNavigate();
    return (
        <a
            href={to}
            onClick={(event) => {
                event.preventDefault();
                navigate(to,{state:{id:1, name:"test"}});
            }}
        >
            {children}
        </a>
    );
}

function PageWithPath() {
    const location =  useLocation();
    console.log(location.state)
    return <h2>Page with path</h2>;
}

is @forge/bridge(v2.1.3) compatible with react-router-dom(v6)? I noted that the version of history library api are different. can anyone please help me with this? Thank you

Hi @hb12devtn,

I’m currently investigating this issue. I’ve been able to reproduce the fact that state is null despite calling navigate with the state.

Just letting you know I’m looking into it and will come back with an update soon.

UPDATE: on a closer look, it does seem to be an issue with the view.createHistory API. I’ve let the team that works on this part of Forge know about the issue, and they’ll look into fixing it.

For now, is it possible to use path parameters or query parameters instead?

@kchan thanks for the response, for now I’m using query parameters hoping that this will be fixed.
Thanks again

2 Likes