| 154 | } |
| 155 | |
| 156 | function createRoutesFromConfig( |
| 157 | children: React.ReactNode, |
| 158 | config: RouterConfig | undefined |
| 159 | ): RouteObject[] { |
| 160 | // By default react-router 6 catches exceptions and displays the stack |
| 161 | // trace. For tests we want them to bubble out |
| 162 | function ErrorBoundary(): React.ReactNode { |
| 163 | throw useRouteError(); |
| 164 | } |
| 165 | |
| 166 | const emptyRoute = { |
| 167 | path: '*', |
| 168 | element: <div>No routes match, check that your location matches your route</div>, |
| 169 | errorElement: <ErrorBoundary />, |
| 170 | }; |
| 171 | |
| 172 | if (config?.route) { |
| 173 | return [ |
| 174 | { |
| 175 | path: config.route, |
| 176 | element: children, |
| 177 | errorElement: <ErrorBoundary />, |
| 178 | children: config.children, |
| 179 | }, |
| 180 | emptyRoute, |
| 181 | ]; |
| 182 | } |
| 183 | |
| 184 | if (config?.routes) { |
| 185 | return [ |
| 186 | ...config.routes.map(route => ({ |
| 187 | path: route, |
| 188 | element: children, |
| 189 | errorElement: <ErrorBoundary />, |
| 190 | children: config.children, |
| 191 | })), |
| 192 | emptyRoute, |
| 193 | ]; |
| 194 | } |
| 195 | |
| 196 | return [{path: '*', element: children, errorElement: <ErrorBoundary />}]; |
| 197 | } |
| 198 | |
| 199 | function makeRouter({ |
| 200 | children, |