DEV Community

Cover image for How to get preact-router working with Netlify
Emma Goto πŸ™
Emma Goto πŸ™

Posted on β€’ Originally published at emgoto.com on

4 2

How to get preact-router working with Netlify

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

References

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

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (1)

Collapse
 
bkachinthay profile image
bkachinthay β€’ β€’ Edited

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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs