简体   繁体   English

使用 saga 添加“createBrowserHistory”后,React 路由器停止工作

[英]React router stopped working after adding "createBrowserHistory" with saga

I'm learning React.js and I struggled with the following problem:我正在学习 React.js,但遇到了以下问题:

My react app stopped working after adding "createBrowserHistory" with Saga.在使用 Saga 添加“createBrowserHistory”后,我的 React 应用程序停止工作。

Essentially, I want to redirect users to the Cart Page (/cart) when I click on "Add to Cart" button.本质上,我想在单击“添加到购物车”按钮时将用户重定向到购物车页面 (/cart)。

Example:例子:

That is the home page:那是主页:

在此处输入图像描述

When I click on "Add to Cart" button, it navigates to the "/cart" route.当我点击“添加到购物车”按钮时,它导航到“/cart”路线。 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:添加历史记录 package:

在此处输入图像描述

Created history file:创建的历史文件:

在此处输入图像描述

Changed App.js file:更改了 App.js 文件:

在此处输入图像描述

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.我在这里创建了一个 Pull Request,以重现错误。 Feel free to have a look at this.随意看看这个。

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

I'm willing to bounty someone who creates a PR for me.我愿意奖励为我创建 PR 的人。 I will also accept your answer here!我也会在这里接受你的回答!

Seems like react-router 5x version are only compatible with history.4x.似乎 react-router 5x 版本只与 history.4x 兼容。

Downgrading the history version to 4.2.0 works.将历史版本降级到 4.2.0 是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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