我已经阅读了有关react-router交换机的文档
我了解有关交换机和路由的定义
但是还是有些不明白
如果我只想选择一条路线进行渲染,我们将使用Switch
<Switch>
<Route exact path="/" component={Home} />
<Route path="/a" component={A} />
<Route path="/b" component={B} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
我无法理解的一点是,没有Switch我就能获得相同的效果
<Route exact path="/" component={Home} />
<Route path="/a" component={A} />
<Route path="/b" component={B} />
Run Code Online (Sandbox Code Playgroud)
那么,为什么要使用Switch?我们什么时候需要使用Switch?
我发现需要使用Switch的情况
如果我想在没有路径匹配时渲染特定的组件
我们需要像这样将Route包装在Switch中
<Switch>
<Route exact path="/" component={Home} />
<Route path="/a" component={A} />
<Route path="/b" component={B} />
<Route component={SpecificComponent} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
我对吗 ?
Apollo 查询在我的 React 应用程序中缓存了错误的数据。
如果我将查询的 fetchPolicy 设置为“仅网络”,则一切正常。
所以我认为这是一个缓存问题。
一直在努力解决问题,看到了关于apollo cache的文章,还是解决不了问题。
以下是我查询后的结果:
参数 memberId 为空(结果正确)
[
{
"id": 87,
"totalQuantity": 12,
"Orders": [
{
"id": 1,
"quantity": 11,
"Member": {
"id": 1,
"name": "A"
}
},
{
"id": 28,
"quantity": 1,
"Member": {
"id": 9,
"name": "B"
}
}
]
},
{
"id": 88,
"totalQuantity": 1,
"Orders": [
{
"id": 2,
"quantity": 1,
"Member": {
"id": 1,
"name": "A"
}
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
参数 memberId 为 9(结果正确)
[
{
"id": …Run Code Online (Sandbox Code Playgroud)