0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

fix: 🐛 detail page will not load new data after route change

This commit is contained in:
Meeeeow 2017-12-02 22:37:03 +08:00 committed by juanpicado
parent f983fa3860
commit 2a69f4e51a
2 changed files with 41 additions and 13 deletions

View file

@ -23,10 +23,20 @@ export default class PackageSidebar extends React.Component {
}
async componentDidMount() {
await this.loadPackageData(this.props.packageName)
}
async componentWillReceiveProps(newProps) {
if (newProps.packageName !== this.props.packageName) {
await this.loadPackageData(newProps.packageName)
}
}
async loadPackageData(packageName) {
let packageMeta;
try {
packageMeta = (await API.get(`sidebar/${this.props.packageName}`)).data;
packageMeta = (await API.get(`sidebar/${packageName}`)).data;
} catch (err) {
this.setState({
failed: true

View file

@ -22,14 +22,32 @@ export default class Detail extends React.Component {
notFound: false,
};
get packageName() {
let params = this.props.match.params;
getPackageName(props = this.props) {
let params = props.match.params;
return `${(params.scope && '@' + params.scope + '/') || ''}${params.package}`;
}
get packageName() {
return this.getPackageName();
}
async componentDidMount() {
await this.loadPackageInfo(this.packageName);
}
async componentWillReceiveProps(newProps) {
let packageName = this.getPackageName(newProps);
if (packageName === this.packageName) return;
await this.loadPackageInfo(packageName);
}
async loadPackageInfo(packageName) {
this.setState({
readMe: ''
});
try {
const resp = await API.get(`package/readme/${this.packageName}`);
const resp = await API.get(`package/readme/${packageName}`);
this.setState({
readMe: resp.data
});