简体   繁体   中英

React router stopped working after adding "createBrowserHistory" with saga

I'm learning React.js and I struggled with the following problem:

My react app stopped working after adding "createBrowserHistory" with Saga.

Essentially, I want to redirect users to the Cart Page (/cart) when I click on "Add to Cart" button.

Example:

That is the home page:

在此处输入图像描述

When I click on "Add to Cart" button, it navigates to the "/cart" route. However, it doesn't show anything and, there is no error in the console.

在此处输入图像描述

I have made the following changes in my code:

Added history package:

在此处输入图像描述

Created history file:

在此处输入图像描述

Changed App.js file:

在此处输入图像描述

Changed saga file. I expect to navigate to the "/cart" route after doing some jobs...

在此处输入图像描述

The problem is here! I want to fix the problem in my saga file only.

I've created a Pull Request here, to reproduce the error. Feel free to have a look at this.

https://github.com/willianfalbo/online-shoes-app/pull/1

I'm willing to bounty someone who creates a PR for me. I will also accept your answer here!

Seems like react-router 5x version are only compatible with history.4x.

Downgrading the history version to 4.2.0 works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM