Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route Generation for route in another hierarchy #625

Open
simonfox opened this issue Nov 14, 2018 · 4 comments
Open

Route Generation for route in another hierarchy #625

simonfox opened this issue Nov 14, 2018 · 4 comments

Comments

@simonfox
Copy link
Contributor

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?

@bigopon
Copy link
Member

bigopon commented Nov 14, 2018

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

@davismj
Copy link
Member

davismj commented Nov 14, 2018

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 ?

@simonfox
Copy link
Contributor Author

simonfox commented Nov 14, 2018

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)

@bigopon
Copy link
Member

bigopon commented Nov 15, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants