From 2ce1d329b0384e69adc1ec23249d7f4b261c5f0b Mon Sep 17 00:00:00 2001 From: MCAxiaz Date: Fri, 5 Apr 2019 20:16:18 -0700 Subject: [PATCH] call createLocation on 'to' regardless of type (#6690) --- packages/react-router/modules/Redirect.js | 5 +-- .../modules/__tests__/Redirect-test.js | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/packages/react-router/modules/Redirect.js b/packages/react-router/modules/Redirect.js index f05dce407c..51cdb385a2 100644 --- a/packages/react-router/modules/Redirect.js +++ b/packages/react-router/modules/Redirect.js @@ -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, diff --git a/packages/react-router/modules/__tests__/Redirect-test.js b/packages/react-router/modules/__tests__/Redirect-test.js index ceae6b98e9..52bb9d2ef7 100644 --- a/packages/react-router/modules/__tests__/Redirect-test.js +++ b/packages/react-router/modules/__tests__/Redirect-test.js @@ -23,7 +23,7 @@ describe("A ", () => { }).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( @@ -34,6 +34,40 @@ describe("A ", () => { ); }).not.toThrow(); }); + + it("doesn't break / throw when rendered with object `to`", () => { + const to = { + pathname: "/path", + state: { + someState: "state" + } + }; + expect(() => { + renderStrict( + + + , + 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( + + + , + node + ); + }).not.toThrow(); + }); }); describe("inside a ", () => {