-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
URL redirect && dispatch
to return promise
#23
Comments
I'd prefer API if there is no loss of scope when used alongside conditionals. |
What do you think about this API? Where a route with redirect looks like this: const router = new Router()
.route('/', ({ redirect }) => redirect('/home')); Another example, when you need to do some async stuff before doing a redirect: const router = new Router()
.router('/p/:id', async action({ redirect }, { id }) {
const url = `/graphql?query={post(id:"${id}"){slug,author{username}}}`;
const resp = await fetch(url, { method: 'post' });
const { data } = await resp.json();
if (data.post) {
redirect(`/${data.post.author.username}/${data.post.slug}`);
}
}); |
@koistya Yep - That would work for my use case! |
@zhming0 yep, adding |
Was this done? If yes, how can i use it? :) |
Thanks @koistya for pretty simple example. I've tried to follow as above. import {resolve} from 'universal-router';
import Router from 'universal-router';
....
request.post({
url: 'http://localhost:8000/account/create/',
form
}, (err, res, body) => {
const router = new Router().route('/', ({redirect}) => redirect('/login'));
}
}); but I got an error about webpack.
I'm using react-starter-kit-react-redux. |
@JeongtaekLim answer regarding your error: #127 (comment) Docs about redirects added. Closing. |
I am trying to think of a way to do redirection.
Here are some examples, of which one requires dispatch to return promise.
Or provide a new api
redirect
(same level ason
)?Apparently second one is better. Maybe adding this will be good?
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/31733774-url-redirect-dispatch-to-return-promise?utm_campaign=plugin&utm_content=tracker%2F18115217&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18115217&utm_medium=issues&utm_source=github).The text was updated successfully, but these errors were encountered: