I'm new to ReactJS, and trying to establish whether I can use it for an app I'm building.
I've created the Sign In and Register pages, but I've got some of the same code in both of them, and I'd like to re-use it instead.
So, currently, I have two standalone pages, built as Components, and Routed like this:
const App = () => (
<Router>
<div>
<Route path={ROUTES.REGISTER} component={RegisterPage} />
<Route path={ROUTES.SIGNIN} component={SignInPage} />
<Route component={SignInPage} />
</div>
</Router>
);
so if I go to /register I see the RegisterPage component, and if I go to /signin I see the SignInPage component. (And if I go to anything else, I see the SignInPage.)
However, I have a few more pages to add, in the same style, and I'd like to be able to have a generic "Landing Page" which shows the appropriate component inside it. Then, once the user has signed in, I want a "Dashboard Page" which shows an appropriate component.
So, LandingPage and DashboardPage will just be wrappers for other components, and I want the Routes to work like this:
'landingpage/SignInPage' - shows the LandingPage style, with the SignIn component inside 'landingpage/Register' - shows the LandingPage style, with the Register component inside 'landingpage' - shows the LandingPage style, with the SignIn component inside 'dashboardpage/' - shows the default Dashboard
I thought I could do something like this:
const App = () => (
<Router>
<div>
<Route path={ROUTES.LANDINGPAGE} component={LandingPage} subPage={SignInForm} />
<Route path={ROUTES.REGISTER} component={LandingPage} subPage={RegisterForm} />
<Route path={ROUTES.SIGNIN} component={LandingPage} subPage={SignInForm} />
<Route path={ROUTES.DASHBOARD} component={DashboardPage} subPage={Overview} />
<Route component={LandingPage} subPage={SignInForm} />
</div>
</Router>
);
but I can't work out the exact syntax. Does "subPage" get passed in as state or a prop? How do I use that to render the page properly?
I can't find anything online to tell me how to do this, which makes me think I might be on the wrong lines. If so, what's the correct way?