【发布时间】:2019-05-17 01:06:50
【问题描述】:
我在尝试使用<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'));
浏览器控制台说我接下来:
警告:失败的道具类型:无效的道具
exact类型为string提供给Route,预计boolean。 在 Route (at src/index.tsx:19) index.js:1452
在上一个警告之后的以下警告完全符合文本逻辑
警告:收到
true的非布尔属性exact。如果要将其写入 DOM,请改为传递字符串: 精确=“真”或精确={value.toString()}。 在一个(由 Context.Consumer 创建) 在链接中(在 App.tsx:25) 在标头中(在 App.tsx:11) 在 div 中(在 App.tsx:10) 在 App 中(由 Context.Consumer 创建) 在路线中(在 src/index.tsx:19) 在 Switch 中(在 src/index.tsx:18) 在路由器中(由 BrowserRouter 创建) 在 BrowserRouter (在 src/index.tsx:17) 在路由器中(由 ConnectedRouter 创建) 在 ConnectedRouter 中(在 src/index.tsx:16) 在提供者中(在 src/index.tsx:15)
所描述的示例位于开源 prj https://github.com/gyerts/react/blob/master/starters/typescript-scss-redux/src/index.tsx#L19
【问题讨论】:
-
您是否也将确切的属性传递给 Link 元素?
-
你使用的是哪个 react 路由器版本?
-
"react-router": "^4.3.1","react-router-dom": "^4.4.0-beta.6","react-router-redux": "^5.0.0-alpha.9",