Reputation: 3703
I need to customize the style of my React.js app based on which client is using it, and I'm trying to pass the client id in the url. The url looks like this:
/#/app/client/dashboard
I created the Rout
using this param:
<Route path="/app/:client/dashboard" component={Dashboard} />
Great. Now I want to retrieve the param in my root component. I tried two things. The first is to see if it's in the props
object:
export default function App(props)
but it's not there.
Then I tried to set the localStorage
with a client item in the Dashboard
component, but that's too late because the App()
function is called before the Dashboard()
function.
Is there any other way to do this?
Upvotes: 1
Views: 404
Reputation: 166
I'm not sure whether this is a right approach. If just the problem needs to be solved, give a try with window.location, as it will give access to the current url
let url = window.location.pathname;
console.log(url);
Upvotes: 1