Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
call createLocation on 'to' regardless of type (#6690)
  • Loading branch information
MCAxiaz authored and timdorr committed Apr 6, 2019
1 parent 10d78bb commit 2ce1d32
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
5 changes: 1 addition & 4 deletions packages/react-router/modules/Redirect.js
Expand Up @@ -43,10 +43,7 @@ function Redirect({ computedMatch, to, push = false }) {
method(location);
}}
onUpdate={(self, prevProps) => {
const prevLocation =
typeof prevProps.to === "string"
? createLocation(prevProps.to)
: prevProps.to;
const prevLocation = createLocation(prevProps.to);
if (
!locationsAreEqual(prevLocation, {
...location,
Expand Down
36 changes: 35 additions & 1 deletion packages/react-router/modules/__tests__/Redirect-test.js
Expand Up @@ -23,7 +23,7 @@ describe("A <Redirect>", () => {
}).not.toThrow();
});

it("doesn't break / throw when rendered with location `to`", () => {
it("doesn't break / throw when rendered with location `to` created from string", () => {
const to = createLocation("/go-out?search=foo#hash");
expect(() => {
renderStrict(
Expand All @@ -34,6 +34,40 @@ describe("A <Redirect>", () => {
);
}).not.toThrow();
});

it("doesn't break / throw when rendered with object `to`", () => {
const to = {
pathname: "/path",
state: {
someState: "state"
}
};
expect(() => {
renderStrict(
<MemoryRouter>
<Redirect to={to} />
</MemoryRouter>,
node
);
}).not.toThrow();
});

it("doesn't break / throw when rendered with location `to` created from object", () => {
const to = createLocation({
pathname: "/path",
state: {
someState: "state"
}
});
expect(() => {
renderStrict(
<MemoryRouter>
<Redirect to={to} />
</MemoryRouter>,
node
);
}).not.toThrow();
});
});

describe("inside a <Switch>", () => {
Expand Down

0 comments on commit 2ce1d32

Please sign in to comment.