question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

github_iconTop GitHub Comments

benshellcommented, Feb 5, 2017

I’m just trying/learning Grommet and quickly ran into this issue as well, with React Router v4. It seems to me that the simplest solution is to create a new component to render Anchor as a span, inside of Link:

import React from 'react';
import { Link } from 'react-router-dom';
import Anchor from 'grommet/components/Anchor';

export default (props) => (
  <Link to={props.to}>
    <Anchor tag="span" primary={props.primary}>{props.children}</Anchor>
  </Link>
);
5reactions
alansouzaticommented, Sep 27, 2016

this.context.router.push(this.props.path); should do the trick.

Here is how we use Grommet Anchor with react-router:

// (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP

import React, { Component, PropTypes } from 'react';
import Anchor from 'grommet/components/Anchor';

/**
* This component is used to augment Grommet anchor
* with routing/history capabilities
*/
export default class NavAnchor extends Component {

  constructor () {
    super();
    this._onClick = this._onClick.bind(this);
  }

  _onClick (event) {
    event.preventDefault();
    this.context.router.push(this.props.path);
    if (this.props.onClick) {
      this.props.onClick();
    }
  }

  render () {
    const { path } = this.props;
    const { router } = this.context;
    let className = this.props.className || '';
    if (router.isActive(path)) {
      className += ' active';
    }
    let href = router.createPath(path);
    return (
      <Anchor {...this.props} className={className} href={href}
        onClick={this._onClick} />
    );
  }
};

NavAnchor.propTypes = {
  ...Anchor.propTypes,
  onClick: PropTypes.func,
  path: PropTypes.string.isRequired
};

NavAnchor.contextTypes = {
  router: PropTypes.object.isRequired
};

Usage

<NavAnchor path="/docs/accordion">Accordion</NavAnchor>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using anchor tags in react-router 4 - Stack Overflow
To scroll down to your anchor tags, you need to install React Router Hash Link, with: npm install --save react-router-hash-link.
Read more >
5 Remarkable React Router Features (Anchor Links, Query ...
React Router lets us pass data through the URL so that it can be consumed by the linked-to component. Appending this data to...
Read more >
Create A Hash Anchor Link Effect With React-Router
To do this, I used react-router's Link component. I had used the NavLink for my navigation bar to take advantage of its styling...
Read more >
Link v6.6.1 - React Router
A <Link> is an element that lets the user navigate to another page by clicking or tapping on it. In react-router-dom , a...
Read more >
<Link> · React Router
The primary way to allow users to navigate around your application. <Link> will render a fully accessible anchor tag with the proper href....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found