I have an App component which houses various routes. One of those routes renders a Dashboard component, like so:
class App extends Component {
render() {
return (
<Router>
<Switch>
<Route exact path = "/" component={Home} />
<Route exact path = "/about" component={AboutPage}/>
<Route exact path = "/business" component={BusinessPage} />
<Route exact path = "/business/dashboard/:business" component={DashBoard} />
<Route exact path = "/business/laundromat/:businessName" component={DefaultPage} />
<Route exact path = "/contact" component={Contact} />
<Route exact path = "/login" component={LoginPage} />
<Route exact path = "/sign-up" component={SignUpPage} />
<Route exact path = "/:category/:zipCode" component={SearchPage} />
<Route path="*" component={NotFound}/>
</Switch>
</Router>
);
}
}
export default App;
This component is stateful and passes data as props to various children components. This works fine. However, when I click on links to these components, the URL does not change. I have decided to use "react-router-dom" and the useRouteMatch hook to create nested components. I believe I have it setup correctly, but when I click on Links to these nested components I get my 404 page which is handled on my App component.
I am simply appending /business-info (etc) to the Path mentioned above within my Dashboard Component. I would like to avoid nesting these routes within my App, but every time I click on one of these links it hits the catch all 404 path. Is it possible to append text after a :param? I only have access to the data I need to pass down within the Dashboard... Here is what my route looks like within my Dashboard Component:
import { useRouteMatch, Link, Route, Switch } from 'react-router-dom';
import BusinessInfo from "../components/DashboardBusinessInfo";
import AccountInfo from "../components/DashboardAccountInfo";
import Services from "../components/DashboardServices";
const {path, url} = useRouteMatch();
<Switch>
<Route path={`${path}/business-info`} element={
<BusinessInfo
name={stateObject.businessName}
phone={stateObject.phone}
address={stateObject.address}
category={stateObject.categoryName}
hours={stateObject.hours}
website={stateObject.website}
zip={stateObject.zip}
city={stateObject.city}
street={stateObject.street}
setLink = {selectLinks}
update={updateCall}
/>}
/>
<Route path={`${path}/account-info`} element={<AccountInfo businessName={stateObject.businessName} setLink = {selectLinks}/>}/>
<Route path={`${path}/services`} element={
<Services
category={linkControl.servicesCategory}
data={stateObject}
update={updateCall}
/>}
/>
</Switch>
Version: react-router-dom@5.2.0