0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-27 22:59:51 -05:00

chore: fix router issue with scope packages

This commit is contained in:
Juan Picado @jotadeveloper 2019-01-23 22:09:49 +01:00
parent d3cc419719
commit 34424b5448
No known key found for this signature in database
GPG key ID: 18AC54485952D158
2 changed files with 13 additions and 9 deletions

View file

@ -9,6 +9,7 @@ import Loading from '../../components/Loading';
import DetailContainer from '../../components/DetailContainer';
import DetailSidebar from '../../components/DetailSidebar';
import { callDetailPage } from '../../utils/calls';
import { getRouterPackageName } from '../../utils/package';
export const DetailContext = React.createContext();
@ -21,7 +22,7 @@ class VersionPage extends Component<any, any> {
this.state = {
readMe: '',
packageName: this.getPackageName(props),
packageName: getRouterPackageName(props.match),
packageMeta: null,
isLoading: true,
notFound: false,
@ -32,13 +33,6 @@ class VersionPage extends Component<any, any> {
await this.loadPackageInfo();
}
getPackageName(props: any = this.props): string {
const { match } = props;
const packageName = match.params.package;
return packageName;
}
/* eslint no-unused-vars: 0 */
async componentDidUpdate(nextProps: any, prevState: any) {
const { packageName } = this.state;
@ -56,7 +50,7 @@ class VersionPage extends Component<any, any> {
static getDerivedStateFromProps(nextProps: any, prevState: any) {
const { match } = nextProps;
const packageName = match.params.package;
const packageName = getRouterPackageName(match);
if (packageName !== prevState.packageName) {
try {

View file

@ -106,3 +106,13 @@ export function formatDate(lastUpdate) {
export function formatDateDistance(lastUpdate) {
return distanceInWordsToNow(new Date(lastUpdate));
}
export function getRouterPackageName(match) {
const packageName = match.params.package;
const scope = match.params.scope;
if (scope) {
return `@${scope}/${packageName}`;
}
return packageName;
}