React Router Link not updated with React Slick fade: true;
See original GitHub issueHello,
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:
- Created 5 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Your example, using my suggested workaround: CodeSandbox
Oh good idea, thanks !