26

I'm using react-router@4.1.1

└─┬ react-router@4.1.1
  ├─┬ history@4.6.1
  │ ├── resolve-pathname@2.1.0
  │ └── value-equal@0.2.1
  └── warning@3.0.0

and this message appears in development when attaching a react-router Link

./src/containers/FilterLink.js
37:4-8 'react-router' does not contain an export named 'Link'.

This is the import code:

import React from 'react';
import { Link } from 'react-router';

By the way changing version to react-router@2.0.1 seems to be working.
Does anyone know if Link was removed from react-router? what happened with Link?

If not, why do I get this error?

Evhz
  • 8,852
  • 9
  • 51
  • 69

1 Answers1

73

4.x introduced some breaking changes, you'll need to import Link from react-router-dom:

CommonJS

var Link = require('react-router-dom').Link

ES6 Modules

import { Link } from 'react-router-dom'

Take a peek here for some additional background: https://github.com/ReactTraining/react-router/tree/master/packages/react-router-dom

lux
  • 8,315
  • 7
  • 36
  • 49
  • does it provide any side effect when combined with browserHistory from react-router? – Evhz May 30 '17 at 16:12
  • @Karlos If you do something like ``, that will most likely have to change. They really did completely rewrite 4.x - have a look here: https://stackoverflow.com/questions/42701129/how-to-push-to-history-in-react-router-v4 – lux May 30 '17 at 16:17
  • I see router 4.x breaks rendering flow with react-dom render, even if using Router, Route from react-router-dom. I would like to minimize the refactoring of the code for this change, so decide whether to use 4.x with compatible versions of react-dom or just keep using react-router < 4.x – Evhz May 30 '17 at 16:24
  • @Karlos To be honest, the refactoring from 2/3.x to 4.x was just too much of a burden. I'm currently sticking with 3.x on all my projects, I just don't like the 4.x API at all. – lux May 30 '17 at 16:26
  • @Karlos If npm allowed us to dig into which versions of a project get downloaded the most, that would be valuable, since I'm assuming most folks are sticking it out on 3.x as well: https://stackoverflow.com/questions/43406069/determine-most-popular-version-of-a-given-npm-package – lux May 30 '17 at 16:28
  • I see, I do prefer previous versions of react-router too. I will use a good version of 3.x and force any future react-router package.json deps to be 3.x – Evhz May 30 '17 at 16:29
  • 1
    @Karlos Clicked the chat by accident, feel free to disregard. And I think that's a safe call, AFAIK, they will be supporting 3.x indefinitely, so upgrading to 4.x is not at all required. – lux May 30 '17 at 16:30
  • Following a tutorial that's less than a year old and I'm having to set my version to 3 as well. – Rob Grant Jun 30 '17 at 11:05
  • 1
    Don't forget to install the `react-router-dom` package instead of `react-router`: `npm install --save react-router-dom` – Joshua Pinter May 17 '18 at 22:19