-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
next export default pages #1972
Comments
@herrstucki we will eventually do it with some feedback from the community. |
But we are keep looking at the different options. Help us to figure out the best way to do this. |
A few thoughts:
// This map will be used by default dev and prod server also
exports.pathMap = {
'/foo/:id': ({id}) => ({ page: '/foo', query: {id} })
}
// Exported paths are separated from the mapping
exports.exportPaths = [
...defaultExportPaths(),
'/foo/bar',
'/foo/baz'
] |
This is the intended behaviour. Now you've created a custom URL for your app. |
@arunoda sure, but I'm just lamenting that I'd have to re-create the logic of param-to-query mapping in two places in different ways (server and config). IMO an unnecessary source for confusion and errors. |
@herrstucki you don't need to create it twice. Just create .json file and import and use it both in the server and the config. |
@arunoda yeah, it can be done this way. Still, there's some slight differences (custom server API vs. config API). Not a big deal. I guess you've had more in-depth discussions about core support for custom routes already 😅 But back to the original point: do you see it as a problem to export all pages by default (when no custom routes are used)? |
That's a good point. But there's no way to detect it. |
Yes, but the user knows when they've set up custom routes (see point 2 in #1972 (comment)), so they're already in the customization mindset 🙂 For the case where the user has customized routing but forgot to add
|
Came here b/c I'm currently experiencing some pain due to having no custom routes but many files under I also like the "export all pages by default, show error and ask to add |
In a meantime, here's my workaround which uses // yarn add glob
const glob = require('glob')
exports.exportPathMap = () => {
const pathMap = {}
glob.sync('pages/**/*.js', { ignore: 'pages/_document.js' }).forEach(s => {
const path = s.split(/(pages|\.)/)[2].replace(/^\/index$/, '/')
pathMap[path] = { page: path }
})
return pathMap
} |
Is there a way to make next use pre-compiled pages for production for dynamic urls? For example something like
With this configuration next would serve in production any URL starting with EDIT: I've implemented similar idea here: #3451 |
Implemented in 6.0.0 with #4066 |
Thanks! |
@herrstucki got it right. I learned about nextjs from staticgen.com. I have been evaluating nextjs tonight, and so far, I am able to create pages, etc., even retrieve data without a lot of effort. I'm really looking for a static site generator But after I build, and try to export, I get Why? next seems to be doing so much of the heavy lifting for me. The fact that I have to do any configuration at all in order to export a static version seems to me like this is not the framework that I'm looking for. It's SO close -- it missed the boat entirely. I submitted an issue with staticgen to remove nextjs from the list so more people like me don't waste time with it, unless they really aren't looking for a static-site-generator, in which case it seems like a great framework. |
Next.js 6+ automatically exports all pages inside the |
I just got the latest bits, used the sample, and tried to do an export immediately after a build. |
Here's how to reproduce it:
My package.json:
|
@kasajian
Not sure what you expected from learnnextjs, but as you can see, it's using next 4.2.0 whereas next 6 made exportPathMap optional. |
Thank you. What I expected from learnnextjs is that it wouldn't have the problem that I encountered. I'm just going through the getting-started example on the site. I assume it's going to use the latest bits. |
Hi! Thanks again for
next export
!One question: why is
exportPathMap
in a custom config required? Wouldn't it be a good default to export all the pages? Or at least to provide adefaultExportPathMap
function which could be merged with custom routes?E.g.
The text was updated successfully, but these errors were encountered: