Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

URL redirection does not keep URL parameters #74

Open
federico-paolillo opened this issue Jul 22, 2019 · 2 comments
Open

URL redirection does not keep URL parameters #74

federico-paolillo opened this issue Jul 22, 2019 · 2 comments

Comments

@federico-paolillo
Copy link

federico-paolillo commented Jul 22, 2019

Given this first-level routes:

const routes = {

    '/models': () => <ManageModelsPage />,
    '/company/:companyId*': ({ companyId }) => <CompanyMainPage companyId={companyId} />

};

In the CompanyMainPage component I have the following child routes:

const routes = {

    '/inbound': () => <InboundDevicesPage />

};

Inside the CompanyMainPage component I've setup a redirect from \ to \inbound like so:

function CompanyMainPage({ companyId }) {

    //...

    useRedirect('/', '/inbound');
    const routeResult = useRoutes(routes);

    return routeResult || null;

}

I tought that the URL would be /company/<SOME-GUID>/inbound after redirection but the URL becomes /company/inbound, losing the URL parameter :companyId.

Is there a way to keep the URL parameters after redirection ?

Edit:

By looking more into it I've noticed that the second part of the url (in this example: .../:companyId) gets removed wheter it is a parameter or not.

This happens in router.js:37 when the URL object constructs the new URL, the issue can be avoided if the parameter current ends with a backslash.

See this example (open the Console): https://jsfiddle.net/0bqve6w9/

@Paratron
Copy link
Owner

This seems to be a bug, indeed. As a workaround, can you try to redirect to ./inbound instead of /inbound? Maybe this helps.

@FrobtheBuilder
Copy link

FrobtheBuilder commented Dec 13, 2019

Running into the same issue here. It isn't even specific to redirects, it happens even with normal navigation when your path doesn't end with a slash. Heck, even navigating to ./ blows away the url parameter at the end. It's like it considers non slash-ended paths as "files" rather than "directories", and it considers "./" a level up.
My router chain looks something like /game* -> /:gameId* -> (/, /content/:contentId), with the gameId param specifying a prop to be passed to this detail page, and then the detail page being responsible for showing some specific content as an overlay by navigating relatively. Within that page, when you navigate to content/... or ./content/... or even ./, it destroys that last segment specifying the gameId unless the URL ends with a slash, totally breaking the routing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants