developit / developit/react-router-4-test

Switch does not work

未关闭
#7 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
35
派生
7
PR 合并指标
30 天内没有已合并 PR

描述

**Edit: Just realized pull request /pull/2 is exactly about this**

react-router's [Switch](https://reacttraining.com/react-router/web/api/Switch) looks for a function `Children.forEach` which isn't there. If I try to shim it by
```
Children.forEach = (c, f) => c.forEach(f);
```
then it looks for a function `React.isValidElement`, When it is shimmed as `const isValidElement = (e) => true;`, Switch starts to look for the component's props but the VNode doesn't have it, so Children.forEach should be

```
Children.forEach = (C, f) => {
const compat = C.map(c => ({...c, props: { path: c.attributes.path }}));
return compat.forEach(f);
}
```

which finally results in a `props.match` object returned from Switch. However, one would rather import `preact-compat` instead of rewriting it.

Don't know how this would be solved other than using `preact-compat` when `Switch` or other complex routing elements are needed.

贡献指南

这个仓库没有索引到贡献指南

调研方向

先检查 pull request /pull/2,因为 issue 说它解决了同样的 Switch 不兼容问题。使用 react-router 的 Switch 检查报告的 Children.forEach、React.isValidElement 和 props.match 行为,并验证无需手动 shim 或通过使用 preact-compat 即可正常路由。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, react
领域
frontend, web-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。