kriasoft / universal-router

A simple middleware-style router for isomorphic JavaScript web apps
https://www.kriasoft.com/universal-router/
MIT License
1.7k stars 105 forks source link

Allow non-unique route names #194

Closed frenzzy closed 3 years ago

frenzzy commented 3 years ago

Option uniqueRouteNameSep allows using non-unique route names among different branches of nested routes. The router will automatically generate unique names based on parent routes using the specified separator:

const router = new UniversalRouter([
  { name: 'users', path: '/users', children: [{ name: 'list', path: '/list' }] },
  { name: 'pages', path: '/pages', children: [{ name: 'list', path: '/list' }] },
])
const url = generateUrls(router, { uniqueRouteNameSep: '.' })
url('users.list')                     // => /users/list
url('pages.list')                     // => /pages/list

Closes #193

joezappie commented 3 years ago

Just got a chance to play with this and from what I can tell it works great. I'll definitely be testing it more in depth in the coming week but from my initial tests I've found no issues.

Only thing I found was in the code you use "uniqueRouteNameSep" and in your example above you used "uniqueNameSep". Either of these sound good to me.

Is the preferred method of donation through your open collective link? Really appreciate you adding this in for me and in such little time too!

codecov-commenter commented 3 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (main@518e360). Click here to learn what that means. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             main      #194   +/-   ##
========================================
  Coverage        ?   100.00%           
========================================
  Files           ?         3           
  Lines           ?       229           
  Branches        ?        66           
========================================
  Hits            ?       229           
  Misses          ?         0           
  Partials        ?         0           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 518e360...57cb5bf. Read the comment docs.

frenzzy commented 3 years ago

@jrj2211 thanks for the review, fixed. Sponsor link should work and yes, open collective is the only way of receiving donations we have at the moment.

Released under v9.1.0 🎉