My app.js looks like this:
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
Suggestions?
Redirect is a navigate to a new location, to
accept the URL to redirect to, you can write like this:
<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.
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.
Correct implementation is:
<Redirect to="/auth" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.