@alexseitsinger/previous-pathname-middleware

0.1.0 • Public • Published

Previous Pathname Middleware

Description

Adds the previous pathname to router in redux store.

Usage

In store:

import { createStore, compose, applyMiddleware } from "redux"
import { routerMiddleware } from "connected-react-router"
import previousPathnameMiddleware from "@alexseitsinger/previous-pathname-middleware"

import createRootReducer from "../reducer"

function configureStore(history, initialState = {}) {
	const rootReducer = createRootReducer(history)
	const middleware = [previousPathnameMiddleware, routerMiddleware(history)]
	const storeEnhancers = compose(applyMiddleware(...middleware))
	const store = createStore(rootReducer, initialState, storeEnhancers)
	return store
}

In component:

import React from "react"
import PropTypes from "prop-types"
import { connect } from "react-redux"

function App({ previousPathname }) {
	return <div>App</div>
}

App.propTypes = {
	previousPathname: PropTypes.string.isRequired
}

const mapStateToProps = (state) => {
	return {
		previousPathname: state.router.previousPathname
	}
}

export default connect(mapStateToProps)(App)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    1

Package Sidebar

Install

npm i @alexseitsinger/previous-pathname-middleware

Weekly Downloads

1

Version

0.1.0

License

BSD-2-Clause

Unpacked Size

73.5 kB

Total Files

5

Last publish

Collaborators

  • alexseitsinger