简体   繁体   English

失败的道具类型:提供给“重定向”的无效道具“到”

[英]Failed prop type: Invalid prop `to` supplied to `Redirect`

My app.js looks like this:我的 app.js 看起来像这样:

export default function App() {
  return (
    <BrowserRouter>
      <Switch>
        <Route path="/auth" component={AuthenticationLayout} />
        <Route path="/dash" component={DashboardLayout} />

        <Route exact path="/" render={() => (
          <Redirect to={AuthenticationLayout} />
        )}/>
      </Switch>
    </BrowserRouter>
  );
}

Cant't undersatnd what's the problem Can't undersatnd 有什么问题

Suggestions?建议?

Redirect is a navigate to a new location, to accept the URL to redirect to, you can write like this:重定向是导航到一个新的位置, to URL 重定向到,你可以这样写:

<Route exact path="/" render={() => (
      <Redirect to="/auth" />
    )}/>

The to prop in Redirect accepts either a string, which is the route you want to navigate to, or an object which can contain properties like pathname , state , etc. Redirect 中的to属性接受一个字符串,这是您要导航到的路线,或者一个 object 可以包含诸如pathnamestate等属性。

Ex (from the docs):前(来自文档):

<Redirect
  to={{
    pathname: "/login",
    search: "?utm=your+face",
    state: { referrer: currentLocation }
  }}
/>

So, when you are trying to pass a component to the prop to , you get an error.因此,当您尝试将组件传递给 prop to ,您会收到错误消息。

Correct implementation is:正确的实现是:

<Redirect to="/auth" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 失败的道具类型:提供给“TextInput”的“对象”类型的道具“值”无效 - Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput' 道具类型失败:提供给“输入”的值“搜索”无效的道具“类型” - Failed prop type: Invalid prop `type` of value `search` supplied to `Input` 失败的道具类型:提供给`GlobalState`的`array`类型的无效道具`children` - Failed prop type: Invalid prop `children` of type `array` supplied to `GlobalState` 反应警告:失败的道具类型:提供的“对象”类型的无效道具 - React Warning: Failed prop type: Invalid prop of type `Object` supplied 失败的道具类型:提供给“RCTView”的“对象”类型的无效道具“不透明度” - Failed prop type: Invalid prop `opacity` of type `object` supplied to `RCTView` 提供的道具类型无效 - Invalid prop type supplied 警告:道具类型失败:提供给“路线”的道具属性无效。 在途中 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. in Route 道具类型失败:提供给CardHeader的道具openIcon无效,应该是ReactNode - Failed prop type: Invalid prop openIcon supplied to CardHeader, expected a ReactNode 警告:道具类型失败:提供给“ DropdownItem”的道具“ as”无效 - Warning: Failed prop type: Invalid prop `as` supplied to `DropdownItem` 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM