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.

React Router Link not updated with React Slick fade: true;

See original GitHub issue

Hello,

I have a weird issue when I use React Slick with React Router and Link components.

App.js

import React from "react";
import Slider from "react-slick";
import { BrowserRouter, Link } from "react-router-dom";

import "slick-carousel/slick/slick.css";
import "./styles.css";

function App() {
  const sliderSettings = {
    dots: true,
    infinite: true,
    fade: true,
    slidesToShow: 1,
    slidesToScroll: 1
  };
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>

      <Slider {...sliderSettings} className="carousel">
        <Link to="/page-1">
          <div>
            <img src="https://via.placeholder.com/350x150" />
            Page 1
          </div>
        </Link>
        <Link to="/page-2">
          <div>
            <img src="https://via.placeholder.com/350x150" />
            Page 2
          </div>
        </Link>
        <Link to="/page-3">
          <div>
            <img src="https://via.placeholder.com/350x150" />
            Page 3
          </div>
        </Link>
      </Slider>
    </div>
  );
}

As you can see, every “slide” of the Slick carousel has a Link component with a different “to” props value (page-1, page-2 etc…). However, when the active slide is the page-1 and I click into the slide, I’m redirected to the page-3.

It works as expected if the fade option is false.

You can reproduce it here : CodeSandBox

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

19reactions
robhimslfcommented, Oct 19, 2018

I ran into the same issue. The issue (not really an issue; the library behaves in the least-intrusive manner possible to meet most use cases) is that react-slick simply toggles the opacity on active/inactive slides. It doesn’t set visibility, which is key. Without setting visibility, the last layer in the stack is still able to impact link behavior in the DOM. Depending on your circumstances, this might work for you. It worked for me.

.slick-slide {
  visibility: hidden;
}
.slick-slide.slick-active {
  visibility: visible;
}

Your example, using my suggested workaround: CodeSandbox

1reaction
firestar300commented, Oct 19, 2018

Oh good idea, thanks !

Read more comments on GitHub >

github_iconTop Results From Across the Web

React slick and React router Link doesn't distinguish click and ...
I'm trying to make my slick slider slides link to an about page with react-router-dom . The problem is that it doesn't distinguish...
Read more >
Top 5 react-slick Code Examples - Snyk
Learn more about how to use react-slick, based on react-slick code examples created from the most popular ways it is used in public...
Read more >
Slick Slider Fade Zoom - CodePen
Insecure Resource. The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https....
Read more >
how to get previous path in react router - You.com
Are you trying to get the previous path when the user navigate to new path through address bar or using react-router like this.context.router.push()...
Read more >
Get Started - React Slick Documentation
React slick is a carousel component built with React. It is a react port of slick carousel ... <link rel="stylesheet" type="text/css" charset="UTF-8" ...
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