LearnNewsExamplesServices
Frontmatter
id6923
titleEnhanced Routing with Nested Path Support and Specificity Prioritization
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 1, 2025, 4:07 PM
updatedAtJul 1, 2025, 5:06 PM
githubUrlhttps://github.com/neomjs/neo/issues/6923
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 1, 2025, 5:06 PM

Enhanced Routing with Nested Path Support and Specificity Prioritization

Closed v10.0.0-beta.4 enhancement
tobiu
tobiu commented on Jul 1, 2025, 4:07 PM

Is your feature request related to a problem? Please describe.

The existing routing mechanism in Neo.controller.Base had limitations in handling nested URL paths and resolving conflicts between overlapping routes. Specifically:

  1. The {*paramName} wildcard in route definitions did not correctly capture path segments containing slashes, leading to itemId parameters being undefined for nested routes (e.g., /learn/gettingstarted/Workspaces).
  2. The route matching logic in onHashChange followed a "first match wins" approach, which caused less specific routes (e.g., /learn) to be prioritized over more specific ones (e.g., /learn/{*itemId}), even when a more detailed match was available.

Describe the solution you'd like

The routing system has been enhanced to provide more robust and intuitive behavior for complex URL structures. The key improvements are:

  1. Correct Wildcard Parsing: The {*paramName} and {...paramName} syntaxes now correctly capture entire nested path segments, including slashes, making them suitable for hierarchical content navigation.
  2. Specificity-Based Route Matching: The onHashChange method now intelligently selects the most specific matching route. This prioritization is based on:
    • The length of the matched URL segment (longer matches are preferred).
    • The number of slashes in the route pattern (more slashes indicate deeper nesting and higher specificity).
  3. Improved Documentation: The src/controller/Base.mjs file has been updated with intent-driven comments and examples to clearly explain the enhanced routing capabilities and their usage.

Describe alternatives you've considered

Manually parsing the URL hash within individual route handlers was a cumbersome alternative, but it lacked the declarative and robust nature of a framework-level routing solution.

Additional context

These changes significantly improve the flexibility and predictability of routing within Neo.mjs applications, particularly for applications with deep navigation structures like documentation or content management systems. For example, a route like '/learn/{*itemId}': 'onRouteLearnItem' can now effectively handle nested paths.

Modified Files:

  • src/controller/Base.mjs: Core routing logic and documentation updates.
  • apps/portal/view/learn/MainContainerController.mjs: '/learn/{*itemId}'
  • apps/portal/view/learn/ViewportController.mjs: '/learn/{*itemId}'
tobiu assigned to @tobiu on Jul 1, 2025, 4:07 PM
tobiu added the enhancement label on Jul 1, 2025, 4:07 PM
tobiu referenced in commit bce0772 - "Enhanced Routing with Nested Path Support and Specificity Prioritization #6923" on Jul 1, 2025, 4:08 PM
tobiu referenced in commit addd7ae - "#6923 code cleanup" on Jul 1, 2025, 4:41 PM
tobiu closed this issue on Jul 1, 2025, 5:06 PM