router icon indicating copy to clipboard operation
router copied to clipboard

Route Generation for route in another hierarchy

Open simonfox opened this issue 7 years ago • 4 comments

cc @bigopon (from Gitter)

I'm looking for a way, or at least some router internals that might help, to generate a route from one hierarchy to another.

As a simplified example, assume the following hierarchy

root----client-shell----client-detail
    |
    -----audio-shell----audio-detail

Assume client-detail is the active route, I want to generate a route (or navigate) to the audio-detail route.

I'm currently doing this by defining a route builder module in the audio feature which is exported and used by the client feature. This module understands the route table of the feature and can build a fragment for consumers. I'm just wondering if there is anything existing I can use to support doing something like this?

simonfox avatar Nov 14 '18 09:11 simonfox

cc @davismj I think it's been a long time feature request

bigopon avatar Nov 14 '18 09:11 bigopon

If you're looking for a time-effective solution, can you just generate the route by hand? That will be your best bet.

<a href="#/audio/${id}"></a>

If you're using child routers, you can't really do it easily. If you navigate to client-detail and the route information lives in audio-shell, and you've never loaded audio-shell, the information is just not there to generate the route.

If you're not using child routers, you should use route-href, and you can use router.generate(name, params) too.

If you're dead set on having Aurelia libraries generate the route for you the way they do for non-child routes, it would look something like this: https://codesandbox.io/s/p3869rrwz7. However, this is just a complicated way of solving the problem. You'll probably have less of a headache building the route by hand.

To add, @bigopon ?

davismj avatar Nov 14 '18 11:11 davismj

Thanks @davismj this was basically the conclusion I had come to, just wanted to make sure I hadn't missed anything.

Yes we are using child routers (and wouldn't want to change that as they are great).

you've never loaded audio-shell, the information is just not there to generate the route - does this mean that if I had already visited audio-shell this would be possible? Isn't the information about that hierarchy lost as soon as I leave?

Has there ever been any thought or discussion about functionality to enable providing route hierarchies up front that still support child routing (some sort of tree structure where the nodes are module defs)? In my case the two features would understand up front their own hierarchies and could export that to be loaded by the root router at app start up. Then during navigation that tree could be used in place of configureRouter. That would allow me to just share route names and use router.generate(name, params)

simonfox avatar Nov 14 '18 19:11 simonfox

@simonfox Theoretically, after every navigation, the whole mapping table of every branches from every child router can be aggregated into a giant single table. But I don't think it's something can be added easily for current router code base. Maybe it will be easier after TS conversion.

bigopon avatar Nov 15 '18 08:11 bigopon