You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just wanted to say it's a nice little library you have here, very well written.
Wondered if you've got any plans for allowing nested routes to be defined in different files? E.g if you had a route of GET /user it'd be nice if you could define that in the parent router, and instead of running the function to handle that route, it instead points it to a router in another file. Then in that file you could define child routes, E.g GET :id. This would then get setup as GET /users/:id
The text was updated successfully, but these errors were encountered:
reminder for later but this is getting close I think it can be a bit more elegant
functiongetRouteMatcher(path){constsegments=path.split('/');constregexSegments=segments.map(segment=>(segment.startsWith(':') ? '([^/]+)' : segment));constregexString=`^${regexSegments.join('\\/')}$`;returnnewRegExp(regexString);}functionmatchRoute(uri,path){constrouteMatcher=getRouteMatcher(path);constmatch=uri.match(routeMatcher);if(!match)return{matched: false};constparams={};path.split('/').forEach((segment,i)=>{if(segment.startsWith(':'))console.log(segment,match,i)//thre is a bug here with /:param1/:param2params[segment.slice(1)]=match[i-1];});return{matched: true, params };}//https://codesandbox.io/s/stoic-austin-sx84zx?file=/src/index.mjs
Just wanted to say it's a nice little library you have here, very well written.
Wondered if you've got any plans for allowing nested routes to be defined in different files? E.g if you had a route of GET /user it'd be nice if you could define that in the parent router, and instead of running the function to handle that route, it instead points it to a router in another file. Then in that file you could define child routes, E.g GET :id. This would then get setup as GET /users/:id
The text was updated successfully, but these errors were encountered: