Skip to content

Convert Host route tree to react-router v6 Routes - #415

Merged
cigamit merged 3 commits into
ctrliq:mainfrom
blaipr:feature/react-router-host
Jun 15, 2026
Merged

Convert Host route tree to react-router v6 Routes#415
cigamit merged 3 commits into
ctrliq:mainfrom
blaipr:feature/react-router-host

Conversation

@blaipr

@blaipr blaipr commented Jun 14, 2026

Copy link
Copy Markdown
Contributor
SUMMARY

Continues the react-router v5 → v6 route-tree migration. Converts the Host screen's route trees — list, detail, and the nested HostGroups subtree — from the v5 <Switch>/<Route>/<Redirect> API to v6 <Routes>/<Route> via react-router-dom-v5-compat, following the pattern used for the earlier screen conversions.

UI (no behavior change — same URLs, same panels):

  • Hosts.js (list router): <Switch><Routes>; child routes use the element prop; the detail route is /hosts/:id/* so the nested <Host> tree can match the rest of the path.
  • Host.js (detail router): <Switch><Routes> with relative child paths (details, edit, facts, groups/*, jobs); the exact <Redirect> becomes an index route that <Navigate replace>s to details; the catch-all not-found route stays as path="*"; useRouteMatch is replaced with the id route param, and the data routes stay guarded on the loaded host.
  • HostGroups/HostGroups.js (nested subtree): its single absolute-path <Switch> route becomes an index <Route> under the groups/* parent.
  • Tests: the three suites rewritten with renderWithContexts (RTL) to assert real v6 route resolution — each tab panel, the groups subtree, the index redirect, the unknown-sub-route not-found error, and the 404 detail error.
ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • UI
ADDITIONAL INFORMATION
  • Part of the incremental react-router v6 migration; each screen's route tree is independent and converted on its own branch off main.
  • Like InstanceGroup, this converts a parent and its nested in-screen subtree (HostGroups) together so the relative groups/* delegation resolves under the v6 parent.
  • Tests: 12 route-resolution tests across the three converted suites; full screens/Host directory passes (13 suites / 60 tests).
  • npm --prefix awx/ui run lint clean on the changed source.

blaipr added 2 commits June 14, 2026 13:20
Migrate the Host list and detail route trees (including the nested
HostGroups subtree) from the react-router v5 <Switch>/<Route>/<Redirect>
API to v6 <Routes>/<Route> via react-router-dom-v5-compat, following the
pattern used for the earlier screen conversions.

- Hosts.js: <Switch> -> <Routes>; child routes use the element prop;
  the detail route uses /hosts/:id/* so the nested <Host> tree matches
  the rest of the path.
- Host.js: <Switch> -> <Routes> with relative child paths (details,
  edit, facts, groups/*, jobs); the exact <Redirect> becomes an index
  route that <Navigate>s to details; the catch-all not-found route is
  kept as path="*"; useRouteMatch is replaced with the id route param,
  and the data routes stay guarded on the loaded host.
- HostGroups/HostGroups.js (nested subtree): its single absolute-path
  <Switch> route becomes an index <Route> under the groups/* parent.
- Rewrite the three test suites with renderWithContexts (RTL) to assert
  real v6 route resolution: each tab panel, the groups subtree, the
  index redirect, the unknown sub-route not-found error, and the 404.
Under the v6 route tree, v5 router hooks in descendants no longer see the
route match: HostList's useRouteMatch() returned match.url='/' (links to
//add, //:id/details) and HostGroupsList read the host id via v5
useParams() which returned {}. Build HostList links from the literal
/hosts base, and read HostGroupsList's useParams from
react-router-dom-v5-compat.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the Host screen’s routing from react-router v5 (<Switch>, <Redirect>) to react-router v6-style <Routes>/<Route> using react-router-dom-v5-compat, including the nested HostGroups subtree, and updates the associated tests to assert real v6 route resolution.

Changes:

  • Converted Hosts (list) and Host (detail) route trees to <Routes> with element props and an index redirect via <Navigate replace>.
  • Updated HostGroups subtree routing to an index route under the groups parent.
  • Rewrote the Host/Hosts/HostGroups test suites to use RTL renderWithContexts and validate v6 route matching.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
awx/ui/src/screens/Host/Hosts.js Converts Host list-level routing to v6 <Routes> and delegates detail subtree via /hosts/:id/*.
awx/ui/src/screens/Host/Host.js Converts Host detail routing to v6-style nested routes with an index redirect and relative child paths.
awx/ui/src/screens/Host/HostGroups/HostGroups.js Converts HostGroups subtree to v6 <Routes> with an index route.
awx/ui/src/screens/Host/HostList/HostList.js Removes useRouteMatch usage and switches list navigation URLs to absolute host routes.
awx/ui/src/screens/Host/HostGroups/HostGroupsList.js Adjusts router hook imports to align with v5-compat usage for params.
awx/ui/src/screens/Host/Hosts.test.js Rewrites routing assertions using RTL to validate which v6 route branch resolves for a URL.
awx/ui/src/screens/Host/Host.test.js Rewrites detail routing tests with RTL, including index redirect and not-found behaviors.
awx/ui/src/screens/Host/HostGroups/HostGroups.test.js Rewrites subtree routing test with RTL under the same parent route shape as the app.

Comment thread awx/ui/src/screens/Host/HostGroups/HostGroups.js
The nested <Routes> only defined an index route, so an unknown sub-path
under groups/ (e.g. /hosts/:id/groups/something) rendered a blank panel in
v6. Add a path="*" route that renders a not-found ContentError.
@blaipr

blaipr commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 093d8bab07: added a path="*" not-found fallback to the HostGroups routes so unknown sub-paths under groups/ render a ContentError rather than a blank panel.

@cigamit
cigamit merged commit 19275bd into ctrliq:main Jun 15, 2026
@cigamit cigamit self-assigned this Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants