loading...
Cover image for How to get preact-router working with Netlify

How to get preact-router working with Netlify

emma profile image Emma Goto πŸ™ Originally published at emgoto.com on ・1 min read

If you're deploying your Preact app with preact-router to Netlify, you may find that trying to access anything other than the root of your website (e.g. foo.netlify.com/bar) will give you a "Page not found" error.

The recommended approach is to create a build/_redirects file and add this line:

/*/index.html 200

However if this doesn't work for you (it didn't for me), then create a redirects.txt file in your root folder, and add the following to your build command in Netlify:

npm run build && cp redirects.txt build/_redirects

References

Redirect Rules for All; How to configure redirects for your static site
Redirects not working

Posted on by:

emma profile

Emma Goto πŸ™

@emma

Front-end developer. In my spare time I like to make Trello Power-Ups ✨

Discussion

markdown guide
 

This was very helpful!
Small correction though, there needs to be space between pattern and path in redirects.
like so /* /index.html 200