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

Static HTML export adds a trailing slash to URLs #2862

Closed
1 task done
anothertaxi opened this issue Aug 29, 2017 · 5 comments
Closed
1 task done

Static HTML export adds a trailing slash to URLs #2862

anothertaxi opened this issue Aug 29, 2017 · 5 comments

Comments

@anothertaxi
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

I love the new static HTML export functionality in next 3.x, but it is behaving somewhat differently than I would expect. If you have a next.config.js that looks like this:

// next.config.js
module.exports = {
  exportPathMap: function() {
    return {
      "/": {page: "/"},
      "/page2": {page: "/page2"},
    };
  },
};

then I would expect next export to create an out directory like this:

index.html
page2.html

and I would expect Link components that link to /page2 to result in URLs that link to /page2.

Current Behavior

Instead, the config above produces an out directory like this:

index.html
page2/index.html

and Link components that link to /page2 result in URLs that link to /page2/.

Context

I'm trying to make a next site that can be easily hosted on a static server, but this feature means that all of the URLs in the site have an unnecessary trailing slash. This is not only a bit unsightly, but it's also not the same behavior as next start.

Your Environment

Tech Version
next 3.0.6
node 8.2.1
OS macOS Sierra
browser N/A
etc
@sergiodxa
Copy link
Contributor

That's because with simple HTML files (without a custom server router) the only way to avoid the .html is creating a directory with the file name and put a index.html inside, so if you have the file page2.html then you need to go to /page2.html instead of /page2, but if you create the folder you can do /page2/ and avoid the .html

@anothertaxi
Copy link
Author

anothertaxi commented Aug 29, 2017

@sergiodxa Thanks for the response! In my experience, though, that's that's not how a lot of static servers work these days. http-server, for example, will map /page2 to /page2.html automatically, as will Netlify. Which servers are you thinking of that don't automatically map /page2 to /page2.html?

ETA:
These static hosts that I've tested automatically map /page2 to page2.html:

These ones don't automatically map as far as I can tell:

  • now --static
  • S3 requires you to strip .html and set the files' content type to text/html
  • Express's serve-static, although it can be configured with the extensions parameter.
  • Python's SimpleHTTPServer/http.server

@anothertaxi
Copy link
Author

Let me ask this: if I were to make a PR that allowed next export to output /page2.html rather than /page2/index.html, is there a chance it could get accepted?

@arunoda
Copy link
Contributor

arunoda commented Aug 30, 2017

I want this to be the default behavior as this is gonna work without any configurations. And it doesn't hurt.

But I'd like to have an option to remove that and save as .html.

@arunoda
Copy link
Contributor

arunoda commented Aug 30, 2017

Closing this in favor of a PR.

@arunoda arunoda closed this as completed Aug 30, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
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