gpt4 book ai didi

reactjs - react-router-dom 失败的 Prop 类型 : Invalid prop `exact` of type `string`

转载 作者:行者123 更新时间:2023-12-02 20:10:02 27 4
gpt4 key购买 nike

当我尝试使用 <Route /> 时遇到了一些奇怪的警告成分。请关注成行<Route exact={"true"} .../>这使得代码示例下方描述了奇怪的浏览器警告。

ReactDOM.render(
<Provider store={appStore}>
<ConnectedRouter store={appStore} history={history}>
<BrowserRouter>
<Switch>
<Route exact={"true"} path="/" component={App}/>
<Route render={() => <h1>404, not found</h1>} />
</Switch>
</BrowserRouter>
</ConnectedRouter>
</Provider>,
document.getElementById('root'));

浏览器控制台接下来说我:

Warning: Failed prop type: Invalid prop exact of type string supplied to Route, expected boolean. in Route (at src/index.tsx:19) index.js:1452

并且在上一个之后的以下警告在文本逻辑上是绝对恰当的

Warning: Received true for a non-boolean attribute exact.

If you want to write it to the DOM, pass a string instead: exact="true" or exact={value.toString()}. in a (created by Context.Consumer) in Link (at App.tsx:25) in header (at App.tsx:11) in div (at App.tsx:10) in App (created by Context.Consumer) in Route (at src/index.tsx:19) in Switch (at src/index.tsx:18) in Router (created by BrowserRouter) in BrowserRouter (at src/index.tsx:17) in Router (created by ConnectedRouter) in ConnectedRouter (at src/index.tsx:16) in Provider (at src/index.tsx:15)

react-router-dom Failed prop type: Invalid prop 'exact' of type 'string'你能帮我解决这个问题吗?谢谢!

描述的示例位于开源 prj https://github.com/gyerts/react/blob/master/starters/typescript-scss-redux/src/index.tsx#L19

最佳答案

问题是出于某种原因我将属性 exact 传递给了 Link 组件。

<Link exact to="/about">About the author</Link>

所以我删除了 exact 属性,警告消失了。

<Link to="/about">About the author</Link>

关于reactjs - react-router-dom 失败的 Prop 类型 : Invalid prop `exact` of type `string` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53802118/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com