Skip to content
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

Evaluate connected-react-router #125

Open
carlgieringer opened this issue Oct 25, 2022 · 2 comments
Open

Evaluate connected-react-router #125

carlgieringer opened this issue Oct 25, 2022 · 2 comments
Labels
clean code Work to improve the codebase

Comments

@carlgieringer
Copy link
Contributor

connected-react-router appears to be incompatible with history. history.parsePath returns a Location while @types/connected-react-router require a RouterLocation with a query field.

There appear to be ignored issues in the repo:

One alternative seems to be to replace connected-react-router with redux-first-history: https://github.com/salvoravida/redux-first-history.

@carlgieringer carlgieringer added the clean code Work to improve the codebase label Oct 25, 2022
@carlgieringer
Copy link
Contributor Author

carlgieringer commented Dec 15, 2022

Another possibility would be to use react-router with <Navigate> and useNavigate. But I'm unclear how to dispatch navigation from within redux-saga.

I'm a little concerned that react-router hasn't taken support for async routing seriously. This appears in their (old?) docs on v5:

Sometimes you might also need to navigate programmatically, after some asynchronous task that was originally initiated by an action. For example, you might dispatch an action when the user submits a login form. Your thunk, saga or other async handler then authenticates the credentials, then it needs to somehow navigate to a new page if successful. The solution here is simply to include the history object (provided to all route components) in the payload of the action, and your async handler can use this to navigate when appropriate.

https://v5.reactrouter.com/web/guides/deep-redux-integration

But including history in an action payload would probably violate Redux's rule to have serializable actions.

This SO has several options, including the unstable_HistoryRouter and a custom HistoryRouter component.

@carlgieringer
Copy link
Contributor Author

carlgieringer commented Dec 15, 2022

Howdju's use cases appear to be (search for connected-react-router):

  • Update the redux store in response to a navigation. E.g., remove the redirectLocation after the user has navigated or clear the search text when the user navigates. Or clear the page if the user changes location and we will need to refetch the page data (tagPageSlice.)
  • dispatch goBack from components where the user can 'cancel' their interaction. E.g. if the user is at the registration page and cancels, we goBack.
  • Send a page view from a saga that observes location changes.
  • Redirect to login for paths requiring authentication. We should replace this with an HOC withAuth that checks the auth and redirects. That way we colocate a component's auth requirements with the component rather than in flowSagas.js.
  • Redirect home for missing justification root targets. We should probably just stay on the page and tell the user "missing". Or we could redirect from the page.
  • Redirecting after login
  • Navigating to entities after creating them (goto.proposition etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean code Work to improve the codebase
Projects
None yet
Development

No branches or pull requests

1 participant