Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.

Redirect#5

Open
1egoman wants to merge 2 commits intotrunkfrom
redirect-DEN-3327
Open

Redirect#5
1egoman wants to merge 2 commits intotrunkfrom
redirect-DEN-3327

Conversation

@1egoman
Copy link
Copy Markdown
Contributor

@1egoman 1egoman commented May 7, 2018

Add a helper that can be used for redirecting to a different route.

The dashboard uses a pattern similar to this already, though I'm not completely sold on it since this change effectively adds the ability for an action creator that returns nothing (like the redirect action creator) to be a side-effect only action creator and I'm not sure if that's starting down a path of making this project too all-encompassing.

import createRouter, { redirect } from '@density/conduit';

const router = createRouter(store);
router.addRoute('foo/bar', redirect('hello/world'));
router.addRoute('hello/world', () => ({type: "NAVIGATE_TO_HELLO_WORLD"}) );

```
import createRouter, { redirect } from '@density/conduit';

const router = createRouter(store);
router.addRoute('foo/bar', redirect('hello/world'))
router.addRoute('hello/world', () => ({type: "NAVIGATE_TO_HELLO_WORLD"}) )
```
@1egoman 1egoman requested a review from guscost May 7, 2018 14:11
Copy link
Copy Markdown
Contributor

@guscost guscost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but the documentation probably has an error.

Comment thread README.md
import store from './store';

const router = createRouter(store);
router.addRoute('foo/bar', redirect('hello/world'));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being imported directly from the conduit package? Should probably document that if so.

@guscost
Copy link
Copy Markdown
Contributor

guscost commented May 30, 2018

RE: side-effect-only action creator: I'd suggest that this shouldn't be used for hash routes, the normal router navigate is what to use there.

Considering that redirects would/should be going to entirely different web apps, the side effect is really "finish interacting with the app" as far as the app itself is concerned.

@1egoman
Copy link
Copy Markdown
Contributor Author

1egoman commented May 30, 2018

In one way that the dashboard currently uses this functionality, it's going to a different route in the dashboard, not to an external app: https://github.com/DensityCo/dashboard/blob/trunk/src/index.js#L137

But other than for deprecated routes like that (and we probably can get rid of that line now anyway) I agree.

@guscost
Copy link
Copy Markdown
Contributor

guscost commented May 30, 2018

Why can't that be () => router.navigate('spaces/insights') ?

@1egoman
Copy link
Copy Markdown
Contributor Author

1egoman commented May 30, 2018

Because that function returns undefined, this breaks. Currently the redirect implementation in the dashboard is pretty much that only it returns a "dummy" action to get around that issue.

@guscost
Copy link
Copy Markdown
Contributor

guscost commented May 30, 2018

Ah, makes sense.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants