0.0.1 • Published 5 years ago

react-real-location v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

react-real-location

NPM version NPM downloads NPM license Codecov Travis Bundle size

About

Get current location from react-router outside the Switch component

How to Install

First, install the library in your project by npm:

$ npm install react-real-location

Or Yarn:

$ yarn add react-real-location

Getting Started

• Import hook in React application file:

import { useRealLocation } from 'react-real-location';

Returned Values

TypeDescription
LocationCurrent location params

Example

// App.js

import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import { useRealLocation } from 'react-real-location';

import Home from './pages/Home';
import Product from './pages/Product';
import Client from './pages/Client';

const App = () => {
  const { pathname } = useRealLocation();

  return (
    <>
      <p>{pathname}</p>

      <Switch>
        <Route exact path="/" component={Home} />
        <Route path="/product/:id" component={Product} />
        <Route path="/client/:id" component={Client} />

        <Redirect from="*" to="/" />
      </Switch>
    </>
  );
};

export default App;
// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';

import App from './App';

ReactDOM.render(
  <Router>
    <App />
  </Router>,
  document.getElementById('root')
);

License

This project is licensed under the MIT License © 2020-present Jakub Biesiada

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago