From d50bed428b1342be1e001f1188e7c4b35b41e7b1 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 13 May 2026 17:19:59 +0200 Subject: [PATCH] refactor(App): migrate to Data Router for improved routing and unsaved changes handling - Replaced `BrowserRouter` and `Routes` with `createBrowserRouter` and `RouterProvider` to support unsaved changes blocking. - Restructured route definitions for better organization and clarity, maintaining existing functionality. - Added comments to clarify the necessity of the Data Router for handling unsaved changes. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/App.jsx | 213 +++++++++++++++++++++---------------------- 1 file changed, 106 insertions(+), 107 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 2943d4e..5f05dae 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,8 +1,7 @@ import React from 'react' import { - BrowserRouter as Router, - Routes, - Route, + RouterProvider, + createBrowserRouter, Navigate, NavLink, useLocation, @@ -163,115 +162,115 @@ function PublicRoute({ children }) { return !isAuthenticated ? children : } -function AppRoutes() { - return ( - - } /> - - - - - } - /> - - {/* P-01: Öffentliche Rechtstextseiten — kein Auth erforderlich */} - } /> - } /> - } /> - } /> - - }> - } /> - } /> - } /> - } /> - } /> - } /> - - } /> - } /> - } /> - } /> - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - - - - } - /> - } /> - - - } /> - - ) -} +/** + * Data Router — erforderlich für `useBlocker` (ungespeicherte Änderungen). + * Klassisches `BrowserRouter` stellt keinen DataRouterContext bereit; ohne Migration + * werfen Seiten mit `useUnsavedChangesBlocker` beim Rendern eine Invariante. + */ +const appRouter = createBrowserRouter([ + { path: '/verify', element: }, + { + path: '/login', + element: ( + + + + ), + }, + { path: '/impressum', element: }, + { path: '/datenschutz', element: }, + { path: '/nutzungsbedingungen', element: }, + { path: '/medienrichtlinie', element: }, + { + element: , + children: [ + { index: true, element: }, + { path: 'profile', element: }, + { path: 'settings', element: }, + { path: 'settings/system', element: }, + { path: 'settings/legal', element: }, + { path: 'media', element: }, + { + path: 'exercises', + children: [ + { index: true, element: }, + { path: 'new', element: }, + { path: ':id/edit', element: }, + { path: ':id', element: }, + ], + }, + { path: 'clubs', element: }, + { path: 'inbox', element: }, + { path: 'skills', element: }, + { path: 'planning/framework-programs/new', element: }, + { path: 'planning/framework-programs/:id', element: }, + { path: 'planning/framework-programs', element: }, + { path: 'planning/training-modules/new', element: }, + { path: 'planning/training-modules/:id', element: }, + { path: 'planning/training-modules', element: }, + { path: 'planning/run/:unitId/coach', element: }, + { path: 'planning/run/:unitId', element: }, + { path: 'planning', element: }, + { path: 'admin', element: }, + { + path: 'admin/users', + element: ( + + + + ), + }, + { + path: 'admin/hierarchy', + element: ( + + + + ), + }, + { + path: 'admin/maturity-models', + element: ( + + + + ), + }, + { + path: 'admin/catalogs', + element: ( + + + + ), + }, + { + path: 'admin/mediawiki-import', + element: ( + + + + ), + }, + { + path: 'admin/legal-documents', + element: ( + + + + ), + }, + { path: 'trainer-contexts', element: }, + ], + }, + { path: '*', element: }, +]) function App() { return ( - - - + )