IQueryParams.tsx >>
type IQueryParams = { firstParam?: string; secondParam?: string; thirdParam?: boolean; };
app.tsx>>
import React from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; import Body from './router'; interface IProp { } class App extends React.PureComponent<IProp> { constructor(props: IProp) { super(props); this.setQueryParams = this.setQueryParams.bind(this); } componentDidMount() { this.setQueryParams(); } setQueryParams() { const search = window.location.search; const params = new URLSearchParams(search); const params = { firstParam: params.get('firstParam'), secondParam: params.get('secondParam'), thirdParam: params.get('thirdParam'), }; console.log(params); } render() { return ( <Router> <div className="app"> <Body /> </div> </Router> ); } } export default App;
No comments:
Post a Comment