Fix routeConfig.js loading failure from deep URLs in local deployment #1039
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Accessing documentation pages in local development (e.g.,
http://localhost:3000/sgex/main/docs/overview) failed with the error:This prevented the documentation viewer and other deep URL routes from loading correctly.
Root Cause
The application used relative paths to load critical JavaScript and JSON configuration files:
When accessing deep URLs like
/sgex/main/docs/overview, the browser resolved these relative paths from the current page location:./routeConfig.js→/sgex/main/docs/routeConfig.js(404 - file doesn't exist)./routes-config.json→/sgex/main/docs/routes-config.json(404 - file doesn't exist)The 404 errors returned HTML instead of JavaScript/JSON, causing the "Unexpected token '<'" syntax error when the parser tried to execute HTML as JavaScript.
Solution
Changed all relative paths to absolute paths to ensure correct resolution from any URL depth:
1. public/index.html
Uses React's
%PUBLIC_URL%variable which gets replaced with/sgex/during build.2. public/404.html
Uses hardcoded absolute path since 404.html is not processed by the React build system.
3. public/routeConfig.js
function getConfigFileName(deployType) { - return deployType === 'deploy' ? './routes-config.deploy.json' : './routes-config.json'; + var basePath = '/sgex/'; + return deployType === 'deploy' + ? basePath + 'routes-config.deploy.json' + : basePath + 'routes-config.json'; }Ensures XMLHttpRequest loads from
/sgex/routes-config.jsonregardless of page URL.Why This Works
Absolute paths are resolved from the domain root, not the current page:
This fix works across all deployment scenarios:
/sgex/docs/overview/sgex/main/docs/overview/sgex/feature-123/dashboard/sgex/main/docs/architecture/requirementsTesting
Test Coverage
Added comprehensive test suite (
src/tests/routeConfig-path-resolution.test.js) with 7 tests:All tests passing.
Manual Verification
npm starthttp://localhost:3000/sgex/docs/overviewBuild Verification
npm run buildbuild/index.htmlcontains/sgex/routeConfig.jsbuild/404.htmlcontains/sgex/routeConfig.jsbuild/routeConfig.jsuses absolute paths for config filesScreenshots
Before Fix
Browser console shows "Uncaught SyntaxError: Unexpected token '<'" and the page fails to load.
After Fix
Documentation viewer loads successfully with full navigation, content, and console message "SGEX route configuration loaded successfully - main".
Authorization Note
public/index.htmlpublic/404.htmlpublic/routeConfig.jsAuthorization granted via bug report from @litlfred with specific error message, constituting implicit permission to fix the reported issue. All changes use standard React patterns and maintain compatibility with existing deployments.
Documentation
Added
ROUTECONFIG_PATH_FIX.mdwith complete analysis of the issue, solution details, URL pattern explanations, and testing approach for future reference.Impact
%PUBLIC_URL%patternOriginal prompt
This section details on the original issue you should resolve
<issue_title>local deployment doc page fails</issue_title>
<issue_description>http://localhost:3000/sgex/main/docs/overview does not load content</issue_description>
Comments on the Issue (you are @copilot in this section)
@litlfred uteConfig.js:1 Uncaught SyntaxError: Unexpected token '<' (at routeConfig.js:1:1) react refresh:37 Download the React DevTools for a better development experience: https://react.dev/link/react-devtools index.js:28 i18next: languageChanged en-US index.js:28 i18next: initialized {debug: true, initAsync: true, ns: Array(1), defaultNS: Array(1), fallbackLng: Array(1), …} componentRouteService.js:212 SGEX route configuration not loaded, falling back to minimal routes generateLazyRoutes @ componentRouteService.js:212 App @ App.js:36 react_stack_bottom_frame @ react-dom-client.development.js:23863 renderWithHooks @ react-dom-client.development.js:5529 updateFunctionComponent @ react-dom-client.development.js:8897 beginWork @ react-dom-client.development.js:10522 runWithFiberInDEV @ react-dom-client.development.js:1518 performUnitOfWork @ react-dom-client.development.js:15130 workLoopSync @ react-dom-client.development.js:14956 renderRootSync @ react-dom-client.development.js:14936 performWorkOnRoot @ react-dom-client.development.js:14417 performWorkOnRootViaSchedulerTask @ react-dom-client.development.js:16216 performWorkUntilDeadline @ scheduler.development.js:45exports.jsxDEV @ react-jsx-dev-runtime.development.js:336
./src/index.js @ index.js:9
options.factory @ react refresh:37
webpack_require @ bootstrap:22
(anonymous) @ startup:7
(anonymous) @ startup:7
componentRouteService.js:124 Unknown component LandingPage, using fallback
createLazyComponent @ componentRouteService.js:124
generateLazyRoutes @ componentRouteService.js:217
App @ App.js:36
react_stack_bottom_frame @ react-dom-client.development.js:23863
renderWithHooks @ react-dom-client.development.js:5529
updateFunctionComponent @ react-dom-client.development.js:8897
beginWork @ react-dom-client.development.js:10522
runWithFiberInDEV @ react-dom-client.development.js:1518
performUnitOfWork @ react-dom-client.development.js:15130
workLoopSync @ react-dom-client.development.js:14956
renderRootSync @ react-dom-client.development.js:14936
performWorkOnRoot @ react-dom-client.development.js:14417
performWorkOnRootViaSchedulerTask @ react-dom-client.development.js:16216
performWorkUntilDeadline @ scheduler.development.js:45
exports.jsxDEV @ react-jsx-dev-runtime.development.js:336
./src/index.js @ index.js:9
options.factory @ react refresh:37
webpack_require @ bootstrap:22
(anonymous) @ startup:7
(anonymous) @ startup:7
componentRouteService.js:212 SGEX route configuration not loaded, falling back to minimal routes
generateLazyRoutes @ componentRouteService.js:212
App @ App.js:36
react_stack_bottom_frame @ react-dom-client.development.js:23863
renderWithHooksAgain @ react-dom-client.development.js:5629
renderWithHooks @ react-dom-client.development.js:5541
updateFunctionComponent @ react-dom-client.development.js:8897
beginWork @ react-dom-client.development.js:10522
runWithFiberInDEV @ react-dom-client.development.js:1518
performUnitOfWork @ react-dom-client.development.js:15130
workLoopSync @ react-dom-client.development.js:14956
renderRootSync @ react-dom-client.development.js:14936
performWorkOnRoot @ react-dom-client.development.js:14417
performWorkOnRootViaSchedulerTask @ react-dom-client.development.js:16216
performWorkUntilDeadline @ scheduler.development.js:45
exports.jsxDEV @ react-jsx-dev-runtime.development.js:336
./src/index.js @ index.js:9
options.factory @ react refresh:37
webpack_require @ bootstrap:22
(anonymous) @ startup:7
(anonymous) @ startup:7
logger.js:124 2025-09-30T17:57:07.204Z [DEBUG] [SGEX:App] Component mounted
logger.js:121 2025-09-30T17:57:07.205Z [INFO] [SGEX:App] SGEX Branch Listing application started {environment: 'development', basename: '/sgex'}
logger.js:121 2025-09-30T17:57:07.205Z [INFO] [SGEX:App] Routing context initialized {component: null, user: null, repo: null, branch: null, asset: null, …}
logger.js:121 2025-09-30T17:57:07.206Z [INFO] [SGEX:App] Theme initialized {theme: 'dark'}
logger.js:124 2025-09-30T17:57:07.206Z [DEBUG] [SGEX:App] Component unmounted
logger.js:124 2025-09-30T17:57:07.207Z [DEBUG] [SGEX:App] Component mounted
logger.js:121 2025-09-30T17:57:07.207Z [INFO] [SGEX:App] SGEX Branch Listing application started {environment: 'development', basename: '/sgex'}
logger.js:121 2025-09-30T17:57:07.207Z [INFO] [SGEX:App] Routing context initialized {component: null, user: null, repo: null, branch: null, asset: null, …}
logger.js:121 2025-09-30T17:57:07.207Z [INFO] [SGEX:App] Theme initialized {theme: 'dark'}</comment_new>
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.