Add router.use and request.usePath #3

spion opened this Issue Apr 9, 2013 · 2 comments

2 participants


One of the reasons why I find this router is so great is the ability to instantiate multiple routers. You can then write your application as multiple isolated modules, each being .use-d at a different path e.g.

connect.use('/path'. require('./routers/path').route)

You can write middleware that installs multiple routes. For example, an "oauth-flow" middleware requires a "dispatch" route (which redirects the user) and a "callback" route (which is called when the user returns). The oauth-flow middleware can be a separate router which you can install with "app.use" anywhere you like, and you may install multiple such middlewares (say, one for facebook and one for twitter).

The problem is, you can't .use a flask router from within a flask router. router.all exists but unlike app.use its different - it doesn't modify request.url.

So I wrote an extension to flask-router that adds router.use and the property request.usePath (request.originalUrl minus request.url) to make it easier to handle redirects. This extension allows the arbitrary nesting of isolated routers.

However, these probably belong in flask-router. So, if you like the idea I will add them to a fork and write better tests, then submit a pull request. Let me know what you think :)


Sorry for the long time it took to reply, I've been very busy lately.

I think its a good idea and I will certainly merge your extension if you submit and it doesn't break the tests :)


router.use has been implemented so I am going to close this issue

@spion spion closed this May 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment