Answer the question
In order to leave comments, you need to log in
How to create react-router-dom subpages?
Hello everyone, I don't know how to create subpages, I use react-router-dom.
for example, I go to /profile,
and /profile should have a switch and two components /user , /balance-history.
To make the full path look like /profile/user , /profile/balance-history.
the code
class Main extends Component{
render(){
return (
<Switch>
...
<Route path="/profile" component={Profile} />
</Switch>
)
}
}
function Profile(props){
let { path, url } = useRouteMatch();
return(
<div className="page profile-page">
<LoggedControl noLoggedRedirect={true} />
<Redirect to={`${url}/user`} />
<SwitchLinks links={ [
{
link : `${url}/user`,
text : 'Кабинет'
},
{
link : `${url}/balance-history`,
text : 'Платежи'
}
]}/>
<Switch>
<Route path={`${path}/:topic`} component={Control} />
</Switch>
</div>
)
}
function Control(props){
let { topic } = useParams();
if ( topic == 'user' ) return <User />
if ( topic == 'balance-history' ) return <BalanceHistory />
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question