1

I need to grab the value of a key form URL. Let's say the URL is http://localhost:8080/foo=bar. How do I grab the value 'bar' onEnter function with in react-router so that it can be used to trigger other functions.

Thank you in advance.

URL: http://localhost:8080/foo=bar // routes.js var React = require('react'); var ReactRouter = require('react-router'); var Main = require('./templates/main.jsx'); var Sub = require('./templates/sub.jsx'); module.exports = { path: '/', component: Main, indexRoute: { component: Main }, childRoutes: [ { path: '/foo=:bar', component: Sub, onEnter: function(){ // ***************************** // grab the value 'bar' from param } } ] } 

1 Answer 1

1

The onEnter function takes two arguments. nextState and transition. The value you're looking for is inside of nextState.params:

onEnter: function(nextState, transition) { let bar = nextState.params.bar; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.