How to fix React Router not loading CSS for nested pages on refresh?

Sometimes, we want to fix React Router not loading CSS for nested pages on refresh.

In this article, we’ll look at how to fix React Router not loading CSS for nested pages on refresh.

How to fix React Router not loading CSS for nested pages on refresh?

To fix React Router not loading CSS for nested pages on refresh, we should use absolute paths for the href attribute value of the link tag.

For instance, we write

<link rel="stylesheet" href="/style.css" />

to add a link tag with the absolute path /style.css as the value of href.

Conclusion

To fix React Router not loading CSS for nested pages on refresh, we should use absolute paths for the href attribute value of the link tag.