Next.js: Allow setting custom permalink

Created on 16 Mar 2020  路  3Comments  路  Source: vercel/next.js

Feature request

Is your feature request related to a problem? Please describe.

Using Next and Next Export is a great way to generate a static site. Unfortunately, it is not possible to generate non HTML static assets. Adding a custom permalink would allow non important non HTML files. Examples include:

  • RSS (feed.xml)
  • robots.txt
  • Sitemap (sitemap.xml)
  • Netlify CMS Config (admin/config.yml)

Describe the solution you'd like

Add a function or parameter to set the custom permalink for a page. We could also consider making the render function of the React component return a string for the body.

Describe alternatives you've considered

You can generate these files outside of the Next.js build ecosystem but that seems like a lot of extra complexity to the developer experience.

Additional context

This idea was discussed in #9051

Most helpful comment

I know that I can do that if I write the robots.txt by hand. I want the ability to generate static files at build time. I think the sitemap and RSS feed examples are more compelling to be honest.

All 3 comments

This is already possible with Static File Serving feature.

public/robots.txt file will be access in your site via https://example.com/robots.txt

I know that I can do that if I write the robots.txt by hand. I want the ability to generate static files at build time. I think the sitemap and RSS feed examples are more compelling to be honest.

While I think this would be incredibly valuable, here I have a solution that allows you to have a dynamically-generated sitemap that covers dynamic routes and static ones, as an interim solution of sorts:

It uses a lambda for the sitemap generation, routed via @now/node in vercel.json, with the static pages/routes built with a script before deploy.

Maybe it'll help you. It supports static routes, and allows for newly-dynamic pages to still be valid and added (like for products, in that example).

Was this page helpful?
0 / 5 - 0 ratings