11import React , { Component } from "react" ;
22import PropTypes from "prop-types" ;
33import { Link } from "react-router-dom" ;
4- import config from "config" ;
54import validatedNode from "../higher-order/ValidatedNode" ;
65
76class LinkNode extends Component {
@@ -38,20 +37,6 @@ class LinkNode extends Component {
3837 }
3938 }
4039
41- adjustedAttributes ( ) {
42- if ( this . href . startsWith ( "#" ) )
43- return { ...this . props . attributes , to : this . props . attributes . href } ;
44-
45- const parsedURI = new URL ( this . href , config . services . client . url ) ;
46- const { pathname, search : query , hash } = parsedURI ;
47- const adjustedAttributes = { to : { pathname, query } } ;
48- if ( hash ) {
49- adjustedAttributes . to . hash = hash ;
50- }
51- delete Object . assign ( adjustedAttributes , this . props . attributes ) . href ;
52- return adjustedAttributes ;
53- }
54-
5540 renderChildren ( ) {
5641 return React . Children . map ( this . props . children , child => {
5742 if ( React . isValidElement ( child ) ) {
@@ -76,7 +61,12 @@ class LinkNode extends Component {
7661 ) ;
7762 }
7863
79- return < Link { ...this . adjustedAttributes ( ) } > { this . renderChildren ( ) } </ Link > ;
64+ const { href, ...attrs } = this . props . attributes ;
65+ return (
66+ < Link { ...attrs } to = { href } >
67+ { this . renderChildren ( ) }
68+ </ Link >
69+ ) ;
8070 }
8171}
8272
0 commit comments