react-animated-routes
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

react-animated-routes

Small wrapper over the Route and CSSTransition with the ability to override CSSTransition props.

Install

npm i react-animated-routes
# You also need to make sure you have peer dependencies installed
npm i react react-dom react-router-dom react-router-last-location

Basic usage

<AnimatedRoute /> combines <Route /> and <CSSTransition /> logic and props, so it's easier to use:

// You can write
<AnimatedRoute exact path="/page" timeout={300} classNames="fade">
    <div>Page</div>
</AnimatedRoute>

// Instead of
<Route exact path="/page">
  {({ match }) => (
    <CSSTransition
      in={match != null}
      timeout={300}
      classNames="fade"
      unmountOnExit
    >
      <div>Page</div>
    </CSSTransition>
  )}
</Route>

Override props

You can also override CSSTransition props with location state.

To do this, you need to declare <LastLocationProvider /> inside <Router />:

import { BrowserRouter as Router } from 'react-router-dom';
import { LastLocationProvider } from 'react-router-last-location';

const App = () => (
  <Router>
    <LastLocationProvider>...</LastLocationProvider>
  </Router>
);

Then you can override CSSTransition props with history object or Link component:

// Override CSSTransition props
const transition = { timeout: 400, classNames="slide" };

// With history object
history.push('/page', { transition });

// Or Link component
<Link
  to={{
    pathname: '/page',
    state: { transition },
  }}
/>

Demo

See it in action.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.01latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.01
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i react-animated-routes

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

10.4 kB

Total Files

10

Last publish

Collaborators

  • grind-t