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

Keep state in redirection #995

Closed
phoenix377 opened this issue Nov 25, 2016 · 5 comments
Closed

Keep state in redirection #995

phoenix377 opened this issue Nov 25, 2016 · 5 comments

Comments

@phoenix377
Copy link

I need to save store when it is redirected.
I see this project use universal-router.
How should I implement this?

@frenzzy
Copy link
Member

frenzzy commented Nov 25, 2016

Which type of state? There is many ways how you can traverse the state further, for example via url query params, flux/redux/relay store or browser history api.

@phoenix377
Copy link
Author

phoenix377 commented Nov 25, 2016

@frenzzy, thank you for your quick reply.
I want to redirect from index.js of route. It looks like this.

export default {
path: /join',
action({ store, params }) {
...
store.dispatch(...);
return { redirect: /question };
},
};

Here what I want to is to use same store value in /question route. I see that by doing this, in /question route, the store is initialized again.
And store has many data, so sending it through url params is not appropriate I think.
Is there any other method?

@frenzzy
Copy link
Member

frenzzy commented Nov 26, 2016

To prevent reinitialization of store you should create it once inside client.js and just pass through router to your action methods. All your routes will have access to the same store instance in this case and you will be able to share any state between routes.

Here is an example: #883, plus this in client.js:

// ...
const route = await UniversalRouter.resolve(routes, {
  // ...
  store: context.store,
});
// ...

@phoenix377
Copy link
Author

phoenix377 commented Nov 27, 2016

@frenzzy, I'm also using react-intl branch and in my client.js, route is created like below.
const route = await UniversalRouter.resolve(routes, {
...context,
...
}
But still store is refreshed when I redirect.

@ulani
Copy link
Member

ulani commented May 27, 2021

@phoenix377 thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion.

NOTE: The main branch has been updated with React Starter Kit v2, using JAM-style architecture.

@ulani ulani closed this as completed May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants