-
Notifications
You must be signed in to change notification settings - Fork 42
Description
There have been a couple of requests for upgrading to react-router 4, or even making the routing of our app more configurable so that someone can use their own router.
How does routing interact with us-forms-system?
In starting to look into upgrading react-router, we decided to separately investigate the work involved in pulling out routing from the core library. There are several questions I think we need to answer in order to know what this should look like.
- What does the library look like without routing? Would it be usable without any form of routing?
- How does the core concept of pages and chapters work without a concept of routing?
- Would the navigation buttons still exist or would any concept of navigation also be pulled out of the library? How does this impact validation?
- Where does the routing functionality we currently have go? In the starter app, or in an entirely new repo (us-forms-system-router)?
Where is routing currently used in us-forms-system?
There are a few different places in the code where routing comes into play:
createRoutes
Main createRoutes function that generates the list of routes.
Things to think about:
- It would probably be beneficial if users had some control over this function, or at least would be able to overwrite it, like Vets.gov currently does. Then they could add their own logic, like if they assume Introduction and Confirmation pages, which components get rendered by default for each page, etc.
- This could conceivably work for both react-router v3 and v4: for v3 we'd keep it as an object, and for v4 we'd convert it to outputting a hierarchy of React components. Not sure how this would work for entirely different routing libraries.
withRouter() wrappers
We're using the withRouter() function to wrap several of our components. This gives the components access to props that give us control of the routing in those components.
Right now there are several components that are wrapped in withRouter(), but actually only 2 of them make use of it:
<FormPage/>: therouterprop is used to push the next or previous path based on if the user clicked the forward or backward button<SubmitController/>: therouterprop is used to push the previous path based on if the user clicked the backward button
Things to think about:
- How we extract routing from these components largely depends on the answer to questions 2 and 3 at the top: how extracting routing impacts the concepts of pages and navigation. Should we just remove the navigation buttons from these two components entirely and somehow include that separately? Perhaps as wrapping components on the basic form page components?
Helper functions
Helper functions like getNextPagePath, getPreviousPagePath, and others used by createRoutes would need to be pulled out too.
Things that depend on a concept of a "route", but necessarily how to get there
There's some logic around breaking up parts of the form config based on the "route" (see FormPage), and there's some sense of it related to when validations are run and on what fields. But I don't think this stuff has to change in order for us to pull out routing.