fix(routing): handle empty boardPath and resolve directory codes

This commit is contained in:
plebeius
2025-11-07 18:54:45 +01:00
parent 128b6b1986
commit b886cbdf3b
3 changed files with 41 additions and 25 deletions
+5 -2
View File
@@ -1,6 +1,8 @@
import { useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import useSubplebbitsStore from '@plebbit/plebbit-react-hooks/dist/stores/subplebbits';
import { useDefaultSubplebbits } from '../../hooks/use-default-subplebbits';
import { getSubplebbitAddress } from '../../lib/utils/route-utils';
import { HomeLogo } from '../home';
import styles from './not-found.module.css';
import { NOT_FOUND_IMAGES } from '../../generated/asset-manifest';
@@ -16,7 +18,8 @@ const NotFound = () => {
// Extract boardIdentifier from pathname (could be directory code or address)
const pathParts = location.pathname.split('/').filter(Boolean);
const boardIdentifier = pathParts[0] && pathParts[0] !== 'not-found' && pathParts[0] !== 'faq' ? pathParts[0] : '';
const subplebbitAddress = boardIdentifier || '';
const defaultSubplebbits = useDefaultSubplebbits();
const subplebbitAddress = boardIdentifier ? getSubplebbitAddress(boardIdentifier, defaultSubplebbits) : '';
const subplebbit = useSubplebbitsStore((state) => state.subplebbits[subplebbitAddress]);
const { address, shortAddress } = subplebbit || {};
@@ -35,7 +38,7 @@ const NotFound = () => {
<>
<br />
<div className={styles.backToBoard}>
[<Link to={`/${boardIdentifier || subplebbitAddress}`}>Back to p/{shortAddress}</Link>]
[<Link to={`/${boardIdentifier || subplebbitAddress}`}>Back to p/{shortAddress || subplebbitAddress}</Link>]
</div>
</>
)}