Home
Support Forums

Page Not Found after deploy using Public/Private router

My website dev environment:
https://dev--enme.netlify.app/

Build log:

10:20:47 AM: (Netlify Build completed in 59.1s)
10:20:47 AM: Starting post processing
10:20:47 AM: Post processing - HTML
10:20:47 AM: Post processing - header rules
10:20:47 AM: Post processing - redirect rules
10:20:47 AM: Post processing done
10:20:47 AM: Caching artifacts
...
10:20:47 AM: Site is live ✨
...
10:20:48 AM: Build script success
10:21:15 AM: Finished processing build request in 1m49.098458264s

Hi there! I’m using React and react-router-dom in my website. I have two routers: one public and another one private, it depends on userContext.

const Router = (): JSX.Element => {
    const { user } = useContext(UserContext);

    if (!user) {
        return (
            <BrowserRouter>
                <PublicWrapper>
                    <img src="./front-login.png" alt="Front" />
                    <h1>
                        Tome <b>decisões</b> <br /> Mais <b>assertivas</b>{' '}
                    </h1>
                    <aside>
                        <Switch>
                            <Route path="/" component={Login} exact />
                            <Route
                                path="/esqueci-minha-senha"
                                component={ForgottenPassword}
                            />
                            <Route
                                path="/recadastro"
                                component={NewPasswordComponent}
                            />
                        </Switch>
                    </aside>
                </PublicWrapper>
            </BrowserRouter>
        );
    }

    return (
        <BrowserRouter>
            <PrivateWrapper>
                <NavigationMenu />
                <main>
                    <Header />
                    <Switch>
                        <Route path="/" component={Dashboard} exact />
                        <Route path="/pesquisas" component={Surveys} />
                        <Route path="/segmentacao" component={Segmentation} />
                        <Route path="/recompensas" component={Gifts} />
                        <Route path="/respondentes" component={Respondents} />
                        <Route path="/ajuda" component={Help} />
                        <Route path="/configuracoes" component={Settings} />
                    </Switch>
                </main>
            </PrivateWrapper>
        </BrowserRouter>
    );
};

export default Router;

in the public router, the problem is that the route “/recadastro” is returning 404 not found! But i’m facing this problem only after deploy. Locally, i’m not facing this problem in local host.

Any tips?

Hey there, @jgsn.adv :wave:

Thanks so much for reaching out about this.

The first place to look for Page Not Found errors is this Support Guide. Be sure to read the first few comments, as they offer additional steps to take as well:

Up next, I encourage you to work through this thread that also discusses Page Not Found errors with react-router-dom. This seems very relevant to what you are encountering!

Let us know if these help.

1 Like

thank you so much! it worked:

Thanks very much Mr. @jaylowe1 and @luke, it works, just to recap:

  1. Add _redirects file in your public folder
  2. Write down inside file:

/* /index.html 200

In my case I have no issues with my builder adding .txt extension, I’m using CRA(Create React App).

You guys Rock!

1 Like

Great to hear, @jgsn.adv! I am so glad everything is working for you! :netliconfetti:

1 Like