question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

URL redirect && `dispatch` to return promise

See original GitHub issue

I am trying to think of a way to do redirection. Here are some examples, of which one requires dispatch to return promise.

// Redirect / to /home
{on("/", async() => {
     const {state, component} = await this.dispatch("/home");
     return component;
})}

Or provide a new api redirect (same level as on)?

redirct("/", "/home");

Apparently second one is better. Maybe adding this will be good?

<bountysource-plugin> --- 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). </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
koistyacommented, Mar 25, 2016

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}`);
    }
  });
0reactions
frenzzycommented, Oct 8, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Transition to Another Route on Successful Async ...
In this guide, we will use a Redux action to redirect the user using the <Redirect /> component. We will dispatch an action...
Read more >
Returning a dispatch with promises in action creators of react ...
Your first approach was mostly correct. dispatch(thunkAction()) (or in your case this.props.actions.login() returns whatever thunkAction() ...
Read more >
Reactjs – Redux – Change URL when an async action is dispatched ...
Meaning, upon success, the users is "redirected" to another URL (route) the displays a ... userId) { return Promise.all( loadSomeData(dispatch, userId), ...
Read more >
useHooks - Easy to understand React Hook recipes
We bring you easy to understand React Hook code recipes so you can learn how React hooks work and feel more comfortable writing...
Read more >
Node.js Undici
A HTTP/1.1 client, written from scratch for Node.js. ... Returns a promise with the result of the Dispatcher.request method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found