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

Is there a way to print all routes? #2049

Closed
deiga opened this issue Apr 14, 2014 · 4 comments
Closed

Is there a way to print all routes? #2049

deiga opened this issue Apr 14, 2014 · 4 comments

Comments

@deiga
Copy link
Contributor

deiga commented Apr 14, 2014

I recall there used to be app.routes to get this information, what is the current way to do this?

@defunctzombie
Copy link
Contributor

Nope. There is no way to do this since you can mount routers.

@adamsilver
Copy link

What does mount routers mean?

@jmarca
Copy link

jmarca commented Mar 25, 2016

added a note to this effect in the Migrating-from-3.x-to-4.x wiki page.

@totallytavi
Copy link

totallytavi commented Oct 31, 2022

For anyone wondering how to access the routes stored on your Application's router since I needed this and assume someone else might as well. (Assume app is a Express())

// 'bound dispatch' is your routes
const rawRoutes = app._router.stack.filter(l => l.name === "bound dispatch");
// => Array<Layer>
// Layer => {handle: function(), keys: [], name: 'bound dispatch', params: undefined, path: undefined, regexp: undefined, route: {Route}}
// Note: path will be a string if you didn't supply a regular express for the path

const filteredRoutes = app._router.stack.filter(l => l.name === "bound dispatch").map(l => l.route)
// => Route
// Route => {path: "whateverYouSuppliedToTheFunctions", stack: [], methods: {}}

Someone fact check me if this even gets noticed, but I think you can just use <Router>.stack if you need to get routes from a Router

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

5 participants