1.0.12 ā€¢ Published 4 years ago

react-router-link-nostack v1.0.12

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

react-router-link-nostack

npm GitHub PRs Welcome tylim88

šŸŽˆ Prevent stacking in browser history upon re-navigating current route with custom React Router Link Component.

šŸŒŸ almost 0 learning curve.

šŸ”” 0 dependency.

ā›²ļø Out of box typescript support.

šŸ¦ŗ Tested.

Note: You need React Router v5.1 or above to use this!

Installation

npm i react-router-link-nostack

Demo

View it at GhPage!

Try it at Code Sandbox!

Usage

simply use it just like you use React Router Link

import React from 'react'
import { render } from 'react-dom'
import Link from 'react-router-link-nostack'
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import { Helmet } from 'react-helmet'

const Demo = () => {
	return (
		<BrowserRouter basename={'/'}>
			<div>
				<h1>react-router-link-nostack Demo</h1>
				<Link to='/'>to index</Link>
				<br />
				<Link to='/profile'>to profile</Link>
			</div>
			<br />
			<Switch>
				<Route
					exact
					path='/'
					render={() => {
						return (
							<>
								<Helmet>
									<title>Index</title>
								</Helmet>
								<p>Now at Index Page(route: '/')</p>
							</>
						)
					}}
				/>
				<Route
					exact
					path='/profile'
					render={() => {
						return (
							<>
								<Helmet>
									<title>Profile</title>
								</Helmet>
								<p>Now at Profile Page(route: '/profile')</p>
							</>
						)
					}}
				/>
			</Switch>
			<p>
				try to click the same route multiple time and see it wont add to history
				stack!
			</p>
		</BrowserRouter>
	)
}

render(<Demo />, document.getElementById('root'))

API

This Link works like and has the same properties as React Router's Link, plus:

  1. onSamePage(event): callback that trigger when user revisit the same page, can be undefined or null, accept event object.
<Link
	to='/profile'
	onSamePage={() => {
		console.log('same page and wont stack history!')
	}}
>
	to profile
</Link>
1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.3-beta.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.6.17-beta.1

4 years ago

0.6.17-beta.2

4 years ago

0.6.17

4 years ago

0.6.14

4 years ago

0.6.16

4 years ago

0.6.15

4 years ago

0.6.13

4 years ago

0.6.12

4 years ago

0.6.11

4 years ago

0.6.10

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.3

4 years ago

0.5.4

4 years ago

0.6.2

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago