diff --git a/src/components/Link/__tests__/index.js b/src/components/Link/__tests__/index.js
index 363aebd07..c6e5b376c 100644
--- a/src/components/Link/__tests__/index.js
+++ b/src/components/Link/__tests__/index.js
@@ -7,8 +7,9 @@ import expectJSX from "expect-jsx"
import dom from "../../../_utils/jsdom"
import Link from "../"
-dom("http://localhost/test/")
+process.env.PHENOMIC_USER_URL = "http://localhost/test/"
process.env.PHENOMIC_USER_PATHNAME = "/test/"
+dom(process.env.PHENOMIC_USER_URL)
expect.extend(expectJSX)
@@ -67,6 +68,36 @@ test("should render normal tag if to is not 'local'", () => {
.toEqual("http://test.com")
})
+test("should render normal tag if to is not in the same root path", () => {
+ const component = renderer(
+ createElement(
+ Link,
+ {
+ to: "http://localhost/root",
+ className: "foo",
+ children: ,
+ },
+ ),
+ {
+ router: {
+ isActive: () => false,
+ },
+ }
+ )
+
+ expect(component.props.href)
+ .toEqual("http://localhost/root")
+
+ expect(component).toEqualJSX(
+
+
+
+ )
+})
+
test("should allow passing props to tag", () => {
const component = renderer(
createElement(
diff --git a/src/components/Link/index.js b/src/components/Link/index.js
index 2f96c9917..50c059cea 100644
--- a/src/components/Link/index.js
+++ b/src/components/Link/index.js
@@ -38,11 +38,20 @@ function Link(
return simpleLink
}
- const link = document.createElement("a")
- link.href = to
+ const toLink = document.createElement("a")
+ toLink.href = to
if (
- origin(link) === origin(window.location)
+ // parent absolute url with the same domain
+ // should not be Link
+ to.indexOf("://") > -1 &&
+ to.indexOf(process.env.PHENOMIC_USER_URL) === -1
+ ) {
+ return simpleLink
+ }
+
+ if (
+ origin(toLink) === origin(window.location)
// we might want to restrict Link to path including the pathname
// but this will require to preprend pathname to all Links from the
// collection, which sucks.
@@ -50,8 +59,8 @@ function Link(
// you will need to includes the entire url, / won't work at it will use
// the react-router basename defined by Phenomic.
// &&
- // link.pathname.includes(process.env.PHENOMIC_USER_PATHNAME)
- // link.pathname.indexOf(process.env.PHENOMIC_USER_PATHNAME) > -1
+ // toLink.pathname.includes(process.env.PHENOMIC_USER_PATHNAME)
+ // toLink.pathname.indexOf(process.env.PHENOMIC_USER_PATHNAME) > -1
) {
return (