I am working on a project where we have a subscriptions plans container at the home page of the app.....when we are the at the other route where the user need to buy subscription....so there we provide the button to buy subscription....but what i want is when the user click that button i want to route the user to the specific part where the component of the subscriptions plans is......To make this work what i tried is....i gave the parent component of that area an id of subscriptions....then when the user is at different route and he click that button there i also gave a tag with a href of that id i.e. #subscriptions.....but its not working........and i hope you'll understand what i am trying to say.
Asked
Active
Viewed 82 times
-1
-
1put.....some.....code.....please. – Robert Dec 04 '21 at 11:47
-
Okay i am adding some Screenshots of the way i tried it to work – ujjwal sharma Dec 04 '21 at 11:49
-
2Cannot understand your question. Please add some screenshots/code to understand what exactly you are trying to say – Gautam Kothari Dec 04 '21 at 11:53
1 Answers
1
here if the user havn't bought the subscription i want him to route to home page to buy subscription
This is the area where i want the user to route to. (Not the top of the page like a normal react-router do)

ujjwal sharma
- 70
- 6
-
1
-
2
-
-
@AhmadAli it is working the way it should......but there is a issues as tag is refreshing the whole page when clicked which is leading the api to run again as the api is fetching the data really slow its not giving that experince as it is resetting the state again......do you have any other way????..........also again thanks for your previous answer that was working fine – ujjwal sharma Dec 04 '21 at 12:28
-
tehn do it the react way, pass the subscription prop to the history.push(), and receive it on the other component – Ahmad Ali Dec 04 '21 at 12:31
-
-
@AhmadAli onclick={() => history.push("/route#subscriptions"....like this??? – ujjwal sharma Dec 04 '21 at 12:35
-
nope history.push('/',{myprop: 'subscription'}) and recieve my prop on whatever component rendered on route / – Ahmad Ali Dec 04 '21 at 12:37
-
complicated, though, if it on the same page just href="subscription" won't trigger page reload – Ahmad Ali Dec 04 '21 at 12:38
-
@AhmadAli it is actually complicated.....now what i am doing is at at the app.js where my all routes are present i am using render method and as a parameter i am passing the props.....like this render = {(props) =>
}....is it the right way??? – ujjwal sharma Dec 04 '21 at 12:44 -
1