Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
šŸ› Fixed: Phenomic <Link> understand collection links without the ā€¦
Browse files Browse the repository at this point in the history
ā€¦base path

One caveat is now you canā€™t use ``<Link>`` to point to a path before
the current project base path. This is probably and edge case, more
than the case we are fixing here.
We might revisit this issue when refactoring how collection is handled
and  rendered.
  • Loading branch information
MoOx committed Nov 22, 2016
1 parent 8995758 commit f310159
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
6 changes: 5 additions & 1 deletion docs/content/docs/usage/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``<Link>`` to point to a path **before
the current project base path**. This is probably and edge case, more than using
``<Link>`` for project related and collection links.

#### ``BodyContainer``

Expand Down
21 changes: 0 additions & 21 deletions src/components/Link/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,6 @@ test("should render normal <a> tag if to is not 'local'", () => {
.toEqual("http://test.com")
})

test("should render normal <a> tag if to is not in the same root path", () => {
const component = renderer(
createElement(
Link,
{
to: "/root",
className: "foo",
children: <span />,
},
),
{
router: {
isActive: () => false,
},
}
)

expect(component.props.href)
.toEqual("/root")
})

test("should allow passing props to <a> tag", () => {
const component = renderer(
createElement(
Expand Down
12 changes: 10 additions & 2 deletions src/components/Link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<RouterLink
Expand Down
2 changes: 1 addition & 1 deletion themes/phenomic-theme-base/src/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Header = (props, { metadata: { pkg } }) => (
<div className={ styles.navPart1 }>
<Link
className={ styles.link }
to={ "" }
to={ "/" }
>
{ "Home" }
</Link>
Expand Down

0 comments on commit f310159

Please sign in to comment.