preact-router icon indicating copy to clipboard operation
preact-router copied to clipboard

Sorting routes by rank

Open gnaeus opened this issue 9 years ago • 1 comments
trafficstars

<Router> component now sorts routes by count of path segments or by path string length as a fallback.

Maybe it would helpful allow programmers to specify rank explicitly?

This can be done with new rank attribute for route component. Or with using key attribute as rank. Or with preserving order of <Router> component children when counts of path segments are equal (stable sort).

gnaeus avatar Aug 17 '16 07:08 gnaeus

Hey @gnaeus - the stable sort is a really good point, since currently there is nothing defining which route gets precedence when two routes have the same length rank. It seems like it'd be fairly easy to add an explicit rank at the same time as adding stable sort. For just the stability option, perhaps we could make use of the routes' indices within .children?

developit avatar Aug 17 '16 14:08 developit