Open vonwao opened 8 years ago
Hi @vonwao,
I think this is interesting. My thoughts on this:
1) less repetition, you can configure overall module route path in one place. I agree, but you could also use the module config file for for this, or just set up a constant in the routing file. An additional benefit of this approach would be that you don't need to change your top-level routing file, just paste the module and you're good to go.
2) each module has its own "namespace" so no possibility of routes clashing. No clashing would be a great benefit indeed! But we could perhaps also implement a way to test for this.
3) easier to grasp overall app structure by looking at URL. For simpler apps this is true. But the URL does not necessarily reflect the current state of all modules. (I mean state as in machine state here, not necessarily React Component state). Multiple modules may respond to a single route/URL change.
Nonetheless, I think that route-module mapping should be given some thought by the Mantra community.
Just a very wild thought..: perhaps a module-subscribes-to-route pattern would solve this? That may just suit the flat module architecture of design, and should be easy to test against. It would make things highly pluggable, but it is a totally different approach than we have taken so far with Mantra.
I hope @arunoda can shine his light on this.
@sandervanhooft thanks for your comments.
I agree, but you could also use the module config file for for this, or just set up a constant in the routing file.
I guess it's a philosophical question, where this constant belongs. For example, suppose you have a user accounts module, and you have several routes like /login /signup /recoverpassword, etc. Maybe the module defaults to user/login user/register, etc. But maybe as the app developer you import this module but want to mount the routes as account/* instead of user/*. So this feature allows customization.
Just a very wild thought..: perhaps a module-subscribes-to-route pattern would solve this?
I'm not sure what this means, maybe you could give an example?
Anyway, I remembered that FlowRouter does have a "Group Routes" feature: https://github.com/kadirahq/flow-router#group-routes
I'm not sure if this issue will be considered within scope for Mantra, I guess it can be handled with conventions instead of as a feature of mantra. However I still feel a declarative routing API makes app easier to grasp at a high level.
I guess it's a philosophical question I agree! The Mantra specification 0.2 lists a few options about how an app can be composed of one or multiple modules, and what this means for routing configuration.
Just a very wild thought..: perhaps a module-subscribes-to-route pattern would solve this? I don't know if this has been implemented in any framework as of yet. The event-subscriber pattern I am referring to is certainly not new. But I don't know whether this has been tried in a router and what the experience was with this. (It could even be a common used solution on other frameworks, I honestly don't know).
The thing I am thinking of would have a url set (or change) action to be broadcasted as an event to which containers could subscribe to. Instead of defining [route a -> triggers container action b] you would have [container action b happens if event a], where a is an url. This means you can confine the routing configuration to the module and achieve loose coupling.
As I just said, it probably is outside Mantra's scope as we currently use Kadira's FlowRouter, but it may be an interesting path to explore in/for the future.
I wonder if mantra can add a feature for defining routes relative to a module. Why it's helpful:
1) less repetition, you can configure overall module route path in one place. 2) each module has its own "namespace" so no possibility of routes clashing. 3) easier to grasp overall app structure by looking at URL.