I'm building a website with React and using React-Router, I'd like to render a 404 page when a url is visited by the user that doesn't exist.
Some urls are dynamic, say,
www.site.com/user/(username)
How do I render a 404 page with react-router if the user with a particular username doesnt exist? Do I have to manually write code in the component itself during the API calls to check if user exists and then redirect the user to the 404 component?
I'm looking for the best way to redirect the user to a not found page. Looking for ideas on how to do it best.
user/(username). And then either let the component render an error or you can use<Redirect ... />to redirect to a error page as described by @canaan seaton