javascript - Update Url without refreshing page -


i want update url in reactjs app without refreshing page or re-rendering component. how can achieve thing?

i'm trying follows:

this.props.location.query.t = searchquery;     hashhistory.replace(this.props.location); 

but doesn't work in case.

here example more elaboration:

current url: http://localhost:3000/categories/nts

required url: http://localhost:3000/search?subcategory=ntsapp

p.s. have string search?subcategory=ntsapp in searchquery variale

you can use react-router it. let's want update url on button click, _onbuttonclick method. should this:

_onbuttonclick () {     const { pathname } = this.props.location; // asume on page search      // query should object, in case     const query = { subcategory: 'ntsapp' };        this.context.router.replace({         pathname: pathname,         query: query     }) } 

you have specify component contexttypes:

yourcomponent.contexttypes = {     router: react.proptypes.object }; 

above work on top-level components (managed react-router). make work on child components, have pass location in context:

export default class childcomponent extends react.component {      constructor(props) {         super(props);     }      getchildcontext() {         return {             location: this.props.location         };     }  } childcomponent.childcontexttypes = {     location: react.proptypes.object }; 

and use instead of this.props.location. think job :) more information, recommend familiarize react-router api


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -