I have a route <Route path="post/:id" element={<PostByIdPage />} />
How can i get param id as props in react router dom v6?
Here is my PostByIdPage component :
import React, { Component } from 'react';
import OneSecret from '../OneSecret';
import getSecretsPublic from '../../../action/getSecretsPublic';
import { connect } from 'react-redux';
export class index extends Component {
constructor(props) {
super(props);
this.state = {
secretPublic: {
content: ''
}
}
let id = decodeURI(window.location.pathname.substring(6));
let params = {
id: id
}
this.props.getSecretsPublic(params)
.then(res =>{
if (res.type === 'ERROR_MESSAGE') {
return;
}
this.setState({secretPublic: res.payload.data[0]})
});
}
render() {
return (
<div>
<OneSecret element={this.state.secretPublic} key={this.state.secretPublic.id} />
</div>
)
}
}
export default connect(null, {getSecretsPublic})(index)
I'm using window.location.pathname and split to get param but i want to get params from props to re render() my component based in params