So I have a route like in the documentation: <Route path="*"><Redirect to={'/'}/></Route>.
To make sure that all routes lead to '/' if the route doesnt exists.
All my routes work with a <Link> tag but not when I type them in the URL bar.
How can this be? I cant find information about this online.
index file:
return(
<Fragment>
<BrowserRouter basename={`/`}>
<Switch>
<App>
<TransitionGroup>
{routes.map(({ path, Component }) => (
<Route key={path} exact path={`${process.env.PUBLIC_URL}${path}`}>
{({ match }) => (
<CSSTransition in={match != null} timeout={100} classNames={anim} unmountOnExit>
<div><Component/></div>
</CSSTransition>
)}
</Route>
))}
<Route exact path="*"><Redirect to={'/'}/></Route>
</TransitionGroup>
</App>
</Switch>
</BrowserRouter>
</Fragment>
)
Route file:
export const routes = [
{
path:`/`,
Component:Home
},
{
path:`/login`,
Component:Login
},
{
path:`/signup`,
Component:Signup
},
{
path:`/event/:name`,
Component:Event
},
{
path:`/create-event`,
Component:CreateEvent
},
]
Link tag:
<Link to={"/event/" + events[i].name} className="text-dark">