LearnNewsExamplesServices
Frontmatter
id4654
titleCreating a Router for neo
stateClosed
labels
enhancement
assignees[]
createdAtAug 6, 2023, 2:09 PM
updatedAtOct 30, 2023, 10:46 AM
githubUrlhttps://github.com/neomjs/neo/issues/4654
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtOct 30, 2023, 10:46 AM

Creating a Router for neo

Closed v8.1.0 enhancement
tobiu
tobiu commented on Aug 6, 2023, 2:09 PM

Let me explain the current logic first. main.DomEvents will forward hash-change events to the app worker: https://github.com/neomjs/neo/blob/dev/src/main/DomEvents.mjs#L497

worker.App will push the new values into util.HashHistory: https://github.com/neomjs/neo/blob/dev/src/worker/App.mjs#L277

This Singleton will store the last x hash values inside a stack: https://github.com/neomjs/neo/blob/dev/src/util/HashHistory.mjs

Now every controller (including view controllers) will subscribe to the HashHistory change event: https://github.com/neomjs/neo/blob/dev/src/controller/Base.mjs

As a result, developers need to override onHashChange() inside their controllers and act accordingly to modify their views as needed. This can be cumbersome.

It would be nice, if controller.Base would provide a routes_ config, where you can directly specify handlers. This should include variables (could be wrapped inside {}), so we need a bit of regex parsing.

Example how it could be:

routes: {
    '/home'                         : 'handleHomeRoute',
    '/users/{userId}'               : 'handleUserRoute',
    '/users/{userId}/posts/{postId}': 'handlePostRoute',
    'default'                       : 'handleOtherRoutes'
}

The route callback handlers should receive params for the new & old route, as well as used ids inside the route definitions.

Since controller.Base does nothing else except for working with hash related changes, I would drop the logic in there. An alternative would be to extend the class => controller.Router. In this case controller.Component (view controller) would need to extend the router.

tobiu added the enhancement label on Aug 6, 2023, 2:09 PM
tobiu
tobiu Aug 16, 2023, 8:46 PM

The router should be capable of handling private routes (only available when being logged in) otherwise redirect to login.

We could also add role based routes, in case we do want to make it more generic.

ThorstenRaab cross-referenced by PR #5023 on Oct 17, 2023, 8:29 AM
tobiu closed this issue on Oct 30, 2023, 10:46 AM