Convert the Application route tree from react-router v5 Switch to v6 Routes - #400
Conversation
First route-tree conversion of step 2b, on top of the merged v6-compat bridge. Applications.js and Application/Application.js move from v5 <Switch>/<Route>/<Redirect> to v6 <Routes>/<Route element>/<Navigate>: - Applications.js uses absolute paths (it mounts under App.js's v5 ProtectedRoute, so there is no v6 parent route to be relative to); the /applications/:id route gains /* so the nested Application route tree can match the rest. - Application/Application.js uses paths relative to that :id/* parent, with an index route doing the details redirect that <Redirect exact> used to do. The compat package still exports v5 Switch for the ~84 unconverted route trees, so this is isolated and reversible; the react-router-dom -> v6 flip and compat removal stay for the end of step 2b. Both suites are rewritten to RTL and now assert real route resolution through the compat router (renderWithContexts mounts it): each URL renders the expected branch, the index path redirects to details, and the nested tree mounts under a /applications/:id/* parent exactly as the app wires it. Route params are real strings now, not the numbers the old mocked useParams faked.
ApplicationsList and ApplicationForm used match.url (the v5 useRouteMatch prefix) to build links and detect the edit route. With the route tree on v6 there is no useRouteMatch: ApplicationsList always renders at /applications so it builds links from that literal, and ApplicationForm checks useLocation().pathname for the edit suffix. Completes the Application screen's move off v5 router APIs.
There was a problem hiding this comment.
Pull request overview
Migrates the Application screen route trees from react-router v5 <Switch> to v6 <Routes> using react-router-dom-v5-compat, removing remaining v5 useRouteMatch usage in this screen and updating the associated UI tests to assert real route resolution via React Testing Library.
Changes:
- Converted
Applications.jsandApplication/Application.jsto v6-style<Routes>/element={...}routing (with/applications/:id/*to support nested matching). - Replaced v5
useRouteMatchusages in the Application list/form withuseLocation/literal paths for link building and route checks. - Rewrote the Application screen tests from Enzyme to RTL to validate actual routing behavior (list/add/detail subtree, nested tabs, and 404 behavior).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| awx/ui/src/screens/Application/shared/ApplicationForm.js | Replaces useRouteMatch with useLocation().pathname to detect edit mode. |
| awx/ui/src/screens/Application/ApplicationsList/ApplicationsList.js | Removes useRouteMatch; builds links from a fixed /applications base. |
| awx/ui/src/screens/Application/Applications.test.js | Converts to RTL and asserts which v6 <Routes> branch resolves for given URLs. |
| awx/ui/src/screens/Application/Applications.js | Converts top-level Application screen routing to v6 <Routes> and adds /* for nested detail routing. |
| awx/ui/src/screens/Application/Application/Application.test.js | Converts to RTL; mounts under /applications/:id/* and asserts nested tab routing + 404 behavior. |
| awx/ui/src/screens/Application/Application/Application.js | Converts nested detail tabs routing to v6 <Routes> with relative child paths and index redirect. |
The index route redirected to an absolute /applications/${id}/details;
use a relative "details" target so the nested router stays self-contained
and isn't coupled to the parent mount path (review feedback on ctrliq#400).
|
Addressed in 638145a — the index route now redirects with a relative |
|
Having an issue with this one, after creating an application, clicking on tokens or clicking on a token then edit then cancel results in failures |
After the Application route tree moved to v6 <Routes>, descendant components that still read useParams from plain react-router-dom got an empty params object (no v5 <Route> ancestor provides :id anymore), so the application id resolved to undefined — producing requests to /api/v2/applications/undefined/tokens/ and /api/v2/applications/undefined/ when opening Tokens or editing/cancelling. - ApplicationTokenList.js and ApplicationEdit.js: read useParams (and useLocation) from react-router-dom-v5-compat so the id resolves from the v6 route match. - Application.js: the tokens route becomes tokens/* so deeper token URLs still resolve to the list, matching the old non-exact v5 route. - Tests: ApplicationEdit mocks useParams on v5-compat (keeping useNavigate real); ApplicationTokenList gains a regression test that mounts under /applications/:id/tokens/* and asserts readTokens is called with the route id rather than undefined.
|
Good catch, thanks. Fixed in 0c1e469. The problem: once this screen's route tree moved to v6 Routes, a couple of the components underneath it were still importing What I changed:
On the tests:
Whole |
SUMMARY
First of the route-tree conversions, now that the v6-compat bridge has merged. Converts the Application screen's two route-tree files from v5
<Switch>to v6<Routes>, establishing the pattern for the remaining route trees.Applications.js(list / add / detail):<Switch>→<Routes>,<Route path><Child/></Route>→<Route path element={<Child/>} />.ProtectedRoute, so there is no v6 parent route to resolve relative paths against. The/applications/:idroute gains a/*so the nestedApplicationroute tree can match the rest of the path.Application/Application.js(detail tabs):<Switch>→<Routes>,<Redirect from=":id" to=":id/details" exact />→ anindexroute rendering<Navigate replace />./applications/:id/*parent established above (details,edit,tokens).Also clears the screen's remaining v5
useRouteMatch(the remaining "prefix-match" usage):ApplicationsListbuilt links frommatch.urlandApplicationFormcheckedmatch.url.endsWith('edit'). The list always renders at/applicationsso it builds from that literal; the form readsuseLocation().pathname. The Application screen now uses no v5 router APIs.Why this is safe and isolated
The compat package still exports v5
Switchfor the remaining unconverted route trees, so v5 and v6 trees coexist under the single mounted compat router. Nothing outside the Application screen changes. The finalreact-router-dom→ v6 flip and removal ofreact-router-dom-v5-compatstay for the end of the migration, once every<Switch>is gone.Verification
Both suites are rewritten from Enzyme to RTL and now assert real route resolution through the compat router (
renderWithContextsmounts it, the same way the app does):/applicationsrenders the list,/applications/addthe add form,/applications/:id/...the nested detail subtree./applications/:id/*parent route (mounted in the test exactly asApplications.jswires it in the app):details,edit,tokens, and the bare/applications/:idindex path redirecting todetails.One assertion changed meaning for the better: route params are real strings now (
'1'), where the old test mockeduseParamsto return the number1.ISSUE TYPE
COMPONENT NAME
ASCENDER VERSION
ADDITIONAL INFORMATION