簡體   English   中英

失敗的道具類型:提供給“重定向”的無效道具“到”

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

我的 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>
  );
}

Can't undersatnd 有什么問題

建議?

重定向是導航到一個新的位置, to URL 重定向到,你可以這樣寫:

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

Redirect 中的to屬性接受一個字符串,這是您要導航到的路線,或者一個 object 可以包含諸如pathnamestate等屬性。

前(來自文檔):

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

因此,當您嘗試將組件傳遞給 prop to ,您會收到錯誤消息。

正確的實現是:

<Redirect to="/auth" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM