Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shortlist-digital/react-pushstate-anchor

Anchor's that update the browser's location with PushState.
https://github.com/shortlist-digital/react-pushstate-anchor

Last synced: about 2 months ago
JSON representation

Anchor's that update the browser's location with PushState.

Awesome Lists containing this project

README

        

# React PushState Anchor

## What is it?

React PushState Anchor provides three components for performing client-side push state navigation. There's no routing or complex state management. Just three components

![](https://i.imgur.com/e0DcnDS.gif)

### ``

Wrap your entire application or just the part of the application you want to use pushState in.

### ``

A replacement for `` tags that will use `history.pushState` under the hood.

```js
import { PushStateAnchor as A } from 'react-pushstate-anchor'
Home
```

### `PushStateLocation />`

If you're updating history, you'll probably want to know when it's been updated. Use `PushStateLocation` component to get the current history location object, it'll update whenever a `PushStateAnchor` is clicked.
A utitlity component that will provide the current history location using a render callback.

```js
import { PushStateLocaation } from 'react-pushstate-anchor'

{location => {

The current pathname is {location.pathname}


)}

```

## Installation

Install from NPM, `react-pushstate-anchor` requires the `history` module as a peer dependency.

`yarn add react-pushstate-anchor history`

## Usage

```js
import React, { Component } from 'react'
import { PushStateAnchorProvider, PushStateLocation, PushStateAnchor as Psa } from 'react-pushstate-anchor'

class App extends Component {
render() {
return (

Push State Anchor


Home
About
Careers

{location => (

{location.pathname}


)}


)
}
}

export default App
```

`react-pushstate-anchor` will render a simple `` anchor tag if JavaScript is unavailable.