How can i access the current hash location on react router 2?

Vivek Santhosh

I want to access the current location path (like /home) without the history keys for some comparison logic.

How can i access it from the hashHistory in react router 2.

Also, how can i access the previous path?

Alex Chirițescu

You can obtain the current pathname from the location prop of your route component.

Access location from this.props.location of your Route component. If you'd like to get it deeper in the tree, you can use whatever conventions your app has for getting props from high down low. One option is to provide it on context yourself:

// v2.0.x const RouteComponent = React.createClass({
childContextTypes: { location: React.PropTypes.object },

getChildContext() { return { location: this.props.location } } })

Have a look here.

To get the current path, you can just use location.pathname.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I react to URL hash change with Iron Router?

From Dev

How can I react to URL hash change with Iron Router?

From Dev

How to access current location in reducer (redux-router)?

From Dev

How can i access this hash using angular 2

From Dev

How can I get the current GPS location?

From Dev

How can I access an array inside a hash?

From Dev

How can I access current theme colors?

From Dev

How can I access current request in appengine?

From Dev

how to submit html form with current hash location

From Dev

How can I send a Location header relative to the router that is sending the response?

From Dev

How can I get current location on mapview using fragment class?

From Dev

How can I show current location on a Google Map on Android Marshmallow?

From Dev

How can i get the current location? Android Studio

From Dev

How can i get current GPS location ? (not lastknown)

From Dev

how can i get continuous updates of current location in android

From Dev

How can I get accurate latitude/longitude of current GPS location?

From Dev

How can I override Hash native brackets ([] access)

From Dev

How can I allow location access using Selenium?

From Dev

In React Router how can I route to 2 similar urls with a different param

From Dev

With React Redux Router, how should I access the state of the route?

From Dev

Get current location from react-router-redux

From Dev

How can I access a service in a ui-router resolve?

From Dev

How can I access my router settings after installing Apache

From Dev

How can I use a router as a wireless access point?

From Dev

How can I access a service in a ui-router resolve?

From Dev

How can I access the path of the current document in a Jekyll Tag?

From Dev

How can I access the current node from a library in a Chef cookbook?

From Dev

How can I access the number of the dataProvider's current data set?

From Dev

How can i access current woocommerce order shipping method id?

Related Related

  1. 1

    How can I react to URL hash change with Iron Router?

  2. 2

    How can I react to URL hash change with Iron Router?

  3. 3

    How to access current location in reducer (redux-router)?

  4. 4

    How can i access this hash using angular 2

  5. 5

    How can I get the current GPS location?

  6. 6

    How can I access an array inside a hash?

  7. 7

    How can I access current theme colors?

  8. 8

    How can I access current request in appengine?

  9. 9

    how to submit html form with current hash location

  10. 10

    How can I send a Location header relative to the router that is sending the response?

  11. 11

    How can I get current location on mapview using fragment class?

  12. 12

    How can I show current location on a Google Map on Android Marshmallow?

  13. 13

    How can i get the current location? Android Studio

  14. 14

    How can i get current GPS location ? (not lastknown)

  15. 15

    how can i get continuous updates of current location in android

  16. 16

    How can I get accurate latitude/longitude of current GPS location?

  17. 17

    How can I override Hash native brackets ([] access)

  18. 18

    How can I allow location access using Selenium?

  19. 19

    In React Router how can I route to 2 similar urls with a different param

  20. 20

    With React Redux Router, how should I access the state of the route?

  21. 21

    Get current location from react-router-redux

  22. 22

    How can I access a service in a ui-router resolve?

  23. 23

    How can I access my router settings after installing Apache

  24. 24

    How can I use a router as a wireless access point?

  25. 25

    How can I access a service in a ui-router resolve?

  26. 26

    How can I access the path of the current document in a Jekyll Tag?

  27. 27

    How can I access the current node from a library in a Chef cookbook?

  28. 28

    How can I access the number of the dataProvider's current data set?

  29. 29

    How can i access current woocommerce order shipping method id?

HotTag

Archive