Coder Social home page Coder Social logo

trendingtechnology / react-slide-routes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nanxiaobei/react-slide-routes

0.0 0.0 0.0 2.78 MB

๐Ÿ„โ€โ™‚๏ธ The easiest way to slide React routes

License: MIT License

JavaScript 100.00%

react-slide-routes's Introduction

react-slide-routes ๐Ÿ„โ€โ™‚๏ธ

The easiest way to slide React routes

npm npm npm bundle size npm peer dependency version npm peer dependency version GitHub

Fit

react-router version >=4.0.0 and <6.0.0

Add

yarn add react-slide-routes
# or
npm install react-slide-routes

Use

import SlideRoutes from 'react-slide-routes';
import { Route, useLocation } from 'react-router-dom';

const App = () => {
  const location = useLocation();
  return (
    <>
      <SlideRoutes location={location}>
        <Route path="/" component={Home} exact />
        <Route path="/about" component={About} />
        <Route path="/contact" component={Contact} />
      </SlideRoutes>
    </>
  );
};

// If the wrapper of component is <React.Fragment>, only the :first-child will have animation:
// const Home = () => (<> <h1>Title</h1> <div>Content</div> </>);  โ† only <h1> have animation

Live

Play a live demo here โ†’ ๐Ÿคณ

live

API

Prop Type Required Default Description
location object yes location location from react-router-dom, required
duration number 200 transition-duration in milliseconds
effect string 'ease' transition-timing-function, one of 'ease' 'ease-in' 'ease-out' 'ease-in-out' 'linear'
destroy boolean true If false, the passed page will still exits in dom, only invisible

CSS

All css rules for slide effect, can be useful for customization:

/* back */
.back-enter {
  transform: translateX(-100%);
}
.back-enter-active {
  transform: translateX(0);
}
.back-exit {
  transform: translateX(0);
}
.back-exit-active {
  transform: translate(100%);
}

/* next */
.next-enter {
  transform: translateX(100%);
}
.next-enter-active {
  transform: translateX(0);
}
.next-exit {
  transform: translateX(0);
}
.next-exit-active {
  transform: translateX(-100%);
}

License

MIT License ยฉ nanxiaobei

react-slide-routes's People

Contributors

nanxiaobei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.