Javascript React路由器dom和Google webcache内容404错误
这个场景有点具体和棘手。 有一个客户端应用程序是用ReactJS和ReactRouter dom构建的,用于路由。 路由非常基本,如下所示Javascript React路由器dom和Google webcache内容404错误,javascript,reactjs,react-router-dom,Javascript,Reactjs,React Router Dom,这个场景有点具体和棘手。 有一个客户端应用程序是用ReactJS和ReactRouter dom构建的,用于路由。 路由非常基本,如下所示 <Switch> <Route path="/" component={Home} exact/> <Route path="/about" component={About} /> <Route component={404} /> </Switch&
<Switch>
<Route path="/" component={Home} exact/>
<Route path="/about" component={About} />
<Route component={404} />
</Switch>
现在发生的是
<Switch>
<Route path="/about*" component={About} />
<Route path="/404" component={404} />
<Route path="/" component={Home}/>
</Switch>
但仍然在谷歌的webcache中,关于我们
页面将进入主页
用示例更新
为了举例说明问题,更新 我写了一篇关于GoogleWebCache和SEO的文章,这可能会帮助你理解这个问题可能不再那么重要了。
据我从您的代码和解释中了解,您有3条路线: 1)
\
作为项目的根目录
2) 要重定向到的旧匹配项将匹配
3) 将匹配要显示的
组件
未知路由必须是renderNoMatch
组件。
为此,最好在codesandbox
中的example.js
中实现此方法,您在上面提到的路由处理重定向和404组件:
<Switch>
<Route path="/" exact component={Home} />
<Route exact={true} path='/old-match' render={() => { return <Redirect to="/will-match" />; }} />
<Route path="/will-match" component={WillMatch} />
<Route component={NoMatch} />
</Switch>
{return;}}/>
为
保留精确的,在这种情况下,如果URL中附加了任何额外的参数,那么它将是404。不是吗?就像第一个场景一样,您可以在react router to exact routing的route中使用“exact={true}”属性,当url为/关于我们时,它通过插入“”路由来处理重定向到“/”,以捕获404。@behnamshateri可能是我不够清楚<代码>精确
将查找精确匹配。URL的任何动态附加都将转到404。我添加了codesandbox模块来详细说明这个问题。@JustinGeorge:你解决这个问题了吗?如果是这样的话,你能告诉我你是如何解决这个问题的吗?我也有同样的问题。谢谢你的帮助,谢谢你的回答。可能是我没有很好地解释这个问题,你的解决方案不是我想要的。Google webcache使用URL编码和所有内容修改URL。然后,所有子url都不能用于客户端路由。
<Switch>
<Route path="/" exact component={Home} />
<Route exact={true} path='/old-match' render={() => { return <Redirect to="/will-match" />; }} />
<Route path="/will-match" component={WillMatch} />
<Route component={NoMatch} />
</Switch>