-1

change the default localhost path. For example: http://localhost:3001/ by the path http://localhost:3001/home . I would like the when I launch npm start that I arrive directly on this path http://localhost:3001/ home . I tried modifying in the package.Json file, but it doesn't work. Thank you for help

<BrowserRouter>
        <Routes>
          <Route path={"/"}  />
          <Route element={<ViewParentCustomer />} >
            <Route path={RouteTypes.REDIRECT_HOME} element={<Home/>} />
            <Route path={RouteTypes.ROUTE_OUR_HISTORY} element={<OurHistory />} />
           
            
            <Route path={RouteTypes.ROUTE_COMMAND_CUSTOMER_ACCOUNT} element={<ProtectedRoutes ><DetailCommand /></ProtectedRoutes>} />
            <Route path={RouteTypes.ROUTE_SIGNUP} element={<Registration />} />
            <Route path={RouteTypes.ROUTE_FORBIDDEN} element={<AccessForbidden />} /> 
          </Route>

        </Routes>
</BrowserRouter>
tony
  • 199
  • 4
  • 15
  • Hey tony, watch this thread - https://stackoverflow.com/questions/34735580/how-to-do-a-redirect-to-another-route-with-react-router – talm0r Jul 05 '22 at 09:02
  • Does this answer your question? [How to do a redirect to another route with react-router?](https://stackoverflow.com/questions/34735580/how-to-do-a-redirect-to-another-route-with-react-router) – Kapobajza Jul 05 '22 at 09:07
  • the proposed solutions do not work react-router-dom, impossible to import IndexRoute – tony Jul 05 '22 at 09:46
  • Can you include your package.json file, and any other routing/navigation code, as part of your [mcve]? – Drew Reese Jul 05 '22 at 15:57

3 Answers3

0

You can redirect it like this:

<Redirect exact from="/" to="pastry" />

Read more about redirecting here

UPDATE:

You can use Route. Special thanks to Kapobajza:

<Route path="/" element={ <Navigate to="/pastry" /> } />
StepUp
  • 36,391
  • 15
  • 88
  • 148
0

Replace

  <Route path={"/"} element={<Home/>} />

with

<Route path="*" element={<Navigate to="/home" />}/>

Imports:

import {Routes, Route, Navigate} from "react-router-dom";
Priyanshu
  • 73
  • 6
0

the solution : <Route path="/" element={ <Navigate to="/pastry" /> } />

tony
  • 199
  • 4
  • 15
  • Please read [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). While this code block may answer the OP's question, this answer would be much more useful if you explain how this code is different from the code in the question, what you've changed, why you've changed it and why that solves the problem without introducing others. – Saeed Zhiany Jul 07 '22 at 08:10