Gatsby: Path rewrite

Created on 10 Aug 2016  ·  3Comments  ·  Source: gatsbyjs/gatsby

For some pages, I want to to change the URL path in the router to not map directly to the path on the filesystem.

For example: a blog post in a file "blog/2015-01-01-post-title" should have a path "blog/post-title".

Where can I hook into the route building process to change that?

Most helpful comment

Would be really cool if some documentation would be added for rewritePath at some point!

Btw, your blog no longer seems to be using rewritePath. Maybe remove the link...

All 3 comments

Ok, seems like Gatsby automatically rewrites the path if the page has a metadata field "path".

This should really be documented somewhere!

You can also programatically rewrite paths by exporting a rewritePath in gatsby-node.js. Also not documented yet :-

https://github.com/gatsbyjs/gatsby/blob/364a5496ce172e117cc9fc7b10bb1e338693c2ec/lib/utils/build-page/url-resolver.js#L11

See my blog for an example https://github.com/KyleAMathews/blog/blob/master/gatsby-node.js

Would be really cool if some documentation would be added for rewritePath at some point!

Btw, your blog no longer seems to be using rewritePath. Maybe remove the link...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonmp picture brandonmp  ·  3Comments

ferMartz picture ferMartz  ·  3Comments

kalinchernev picture kalinchernev  ·  3Comments

totsteps picture totsteps  ·  3Comments

mikestopcontinues picture mikestopcontinues  ·  3Comments