diff --git a/docs/content/docs/usage/scripting.md b/docs/content/docs/usage/scripting.md index b5ac0b45a..a79f33ff6 100644 --- a/docs/content/docs/usage/scripting.md +++ b/docs/content/docs/usage/scripting.md @@ -57,7 +57,11 @@ Phenomic provides a Link component to cover this case. Current ``react-router`` ``Link`` implementation just crash if you use an external link. Phenomic ``Link`` component fix this for you. This is especially handy if you generate links from unknown data -(eg: markdow front-matter value that can point to internal or external pages) . +(eg: markdow front-matter value that can point to internal or external pages). + +⚠️ One caveat is you can’t use ```` to point to a path **before +the current project base path**. This is probably and edge case, more than using +```` for project related and collection links. #### ``BodyContainer`` diff --git a/src/components/Link/__tests__/index.js b/src/components/Link/__tests__/index.js index 824bea141..363aebd07 100644 --- a/src/components/Link/__tests__/index.js +++ b/src/components/Link/__tests__/index.js @@ -67,27 +67,6 @@ 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: "/root", - className: "foo", - children: , - }, - ), - { - router: { - isActive: () => false, - }, - } - ) - - expect(component.props.href) - .toEqual("/root") -}) - 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 2c3ffb08d..2f96c9917 100644 --- a/src/components/Link/index.js +++ b/src/components/Link/index.js @@ -42,8 +42,16 @@ function Link( link.href = to if ( - origin(link) === origin(window.location) && - link.pathname.indexOf(process.env.PHENOMIC_USER_PATHNAME) > -1 + origin(link) === 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. + // If people wants to use Link for a same domain, but in the parent path, + // 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 ) { return ( (
{ "Home" }