skip to Main Content

I have the following nest route:

createRoutesFromElements(<>                             
        <Route path="/:siteid/:route?/login/:cmd?/:id?" element={< LoginLayout/>}>       
            <Route ... />
            <Route ... />
            <Route path="/:siteid/:route?/login/:cmd?/:id?" element={< LoginPage />} />                                
        </Route>
        <Route...more routes />
    </>)
)

But I get the following error:
Absolute route path "/:siteid/:route/login/:cmd" nested under path "/:siteid/:route/login/:cmd/:id" is not valid.

Just to clarify what I am trying to do – I have several different ways to get to the same login…I just want them all routed to the same place:

e.g.:

/siteid/login 
/siteid/route/login
/siteid/route/login/forgot
/siteid/login/reset/1123

are some examples

Still fairly new on the options ans splats. Any help would be great.

2

Answers


  1. Try below code. I hope this will work.

    createRoutesFromElements(<>                             
        <Route path="/" element={< LoginLayout/>}>       
            <Route ... />
            <Route ... />
            <Route path=":siteid/:route?/login/:cmd?/:id?" element={<LoginPage />} />
        </Route>
        <Route...more routes />
    </>))
    

    <Route path="/" element={< LoginLayout/>}> this is the root. In the props path what ever you put will be starting of all the sub route you are adding in side the root route.

    #HappyCoding

    Login or Signup to reply.
  2. You can make the LoginPage rendered on the layout route’s index route, i.e. matched and rendered when the path is the layout route’s path.

    createRoutesFromElements(
      <>                             
        <Route
          path="/:siteid/:route?/login/:cmd?/:id?"
          element={<LoginLayout />}
        >
          ....
          <Route index element={<LoginPage />} />                                
        </Route>
        ....
      </>
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search