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:
parent
d3cc419719
commit
34424b5448
2 changed files with 13 additions and 9 deletions
|
@ -9,6 +9,7 @@ import Loading from '../../components/Loading';
|
||||||
import DetailContainer from '../../components/DetailContainer';
|
import DetailContainer from '../../components/DetailContainer';
|
||||||
import DetailSidebar from '../../components/DetailSidebar';
|
import DetailSidebar from '../../components/DetailSidebar';
|
||||||
import { callDetailPage } from '../../utils/calls';
|
import { callDetailPage } from '../../utils/calls';
|
||||||
|
import { getRouterPackageName } from '../../utils/package';
|
||||||
|
|
||||||
export const DetailContext = React.createContext();
|
export const DetailContext = React.createContext();
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ class VersionPage extends Component<any, any> {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
readMe: '',
|
readMe: '',
|
||||||
packageName: this.getPackageName(props),
|
packageName: getRouterPackageName(props.match),
|
||||||
packageMeta: null,
|
packageMeta: null,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
notFound: false,
|
notFound: false,
|
||||||
|
@ -32,13 +33,6 @@ class VersionPage extends Component<any, any> {
|
||||||
await this.loadPackageInfo();
|
await this.loadPackageInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
getPackageName(props: any = this.props): string {
|
|
||||||
const { match } = props;
|
|
||||||
const packageName = match.params.package;
|
|
||||||
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint no-unused-vars: 0 */
|
/* eslint no-unused-vars: 0 */
|
||||||
async componentDidUpdate(nextProps: any, prevState: any) {
|
async componentDidUpdate(nextProps: any, prevState: any) {
|
||||||
const { packageName } = this.state;
|
const { packageName } = this.state;
|
||||||
|
@ -56,7 +50,7 @@ class VersionPage extends Component<any, any> {
|
||||||
|
|
||||||
static getDerivedStateFromProps(nextProps: any, prevState: any) {
|
static getDerivedStateFromProps(nextProps: any, prevState: any) {
|
||||||
const { match } = nextProps;
|
const { match } = nextProps;
|
||||||
const packageName = match.params.package;
|
const packageName = getRouterPackageName(match);
|
||||||
|
|
||||||
if (packageName !== prevState.packageName) {
|
if (packageName !== prevState.packageName) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -106,3 +106,13 @@ export function formatDate(lastUpdate) {
|
||||||
export function formatDateDistance(lastUpdate) {
|
export function formatDateDistance(lastUpdate) {
|
||||||
return distanceInWordsToNow(new Date(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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue