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

Any way to get list of available pages / routes? #3351

Closed
1 task done
negamaxi opened this issue Nov 29, 2017 · 3 comments
Closed
1 task done

Any way to get list of available pages / routes? #3351

negamaxi opened this issue Nov 29, 2017 · 3 comments

Comments

@negamaxi
Copy link

negamaxi commented Nov 29, 2017

  • I have searched the issues of this repository and believe that this is not a duplicate.
pages/
  components/
    component.js
  index.js
  catalog.js
  about.js
const listOfPages = await getListOfPages()
console.log(listOfPages)
// [ 'index', 'catalog', 'about' ]

Is it possible to implement such a thing?

@brandonmp
Copy link
Contributor

afaik there's no out-of-the-box way with next. if your structure is that simple, you could just list the directory with fs

we have a ton of dynamically generated pages, so we generate a sitemap.xml w/ next-routes, express-sitemap, and some code that fetches slugs from our db.

we then use sitemapper to turn the xml into a list of urls for tests (though i guess we could just do this while we built the sitemap).

if you don't have a sitemap (which i'm guessing you don't), there's a tool popular among SEOs called screaming frog that'll crawl your site & build an XML sitemap. free up to 500 pages & fairly reliable / credible

@timneutkens
Copy link
Member

@negamaxi you can use https://github.com/zeit/next.js/blob/canary/server/build/webpack.js#L53

const pages = await glob('pages/**/*.js', { cwd: __dirname })

@timneutkens
Copy link
Member

@brandonmp feel free to contribute an example for this. I'm pretty sure there's other people wanting that feature 👌

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants