mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-24 16:58:47 +01:00
Fix title not working when not logged in
Welcome page's useTitle overridden other page's useTitle
This commit is contained in:
parent
be83ca7358
commit
9e867c7af5
2 changed files with 6 additions and 5 deletions
|
@ -6,7 +6,7 @@ import states from '../utils/states';
|
|||
import useTitle from '../utils/useTitle';
|
||||
|
||||
function Welcome() {
|
||||
useTitle();
|
||||
useTitle(null, ['/', '/welcome']);
|
||||
return (
|
||||
<main id="welcome">
|
||||
<h1>
|
||||
|
|
|
@ -9,10 +9,11 @@ const { VITE_CLIENT_NAME: CLIENT_NAME } = import.meta.env;
|
|||
export default function useTitle(title, path) {
|
||||
const snapStates = useSnapshot(states);
|
||||
const { currentLocation } = snapStates;
|
||||
let paths = [];
|
||||
const hasPaths = Array.isArray(path);
|
||||
let paths = hasPaths ? path : [];
|
||||
// Workaround for matchPath not working for optional path segments
|
||||
// https://github.com/remix-run/react-router/discussions/9862
|
||||
if (/:?\w+\?/.test(path)) {
|
||||
if (!hasPaths && /:?\w+\?/.test(path)) {
|
||||
paths.push(path.replace(/(:\w+)\?/g, '$1'));
|
||||
paths.push(path.replace(/\/?:\w+\?/g, ''));
|
||||
}
|
||||
|
@ -24,7 +25,7 @@ export default function useTitle(title, path) {
|
|||
}
|
||||
console.debug({ paths, matched, currentLocation });
|
||||
useEffect(() => {
|
||||
if (path && !matched) return;
|
||||
if (!matched) return;
|
||||
document.title = title ? `${title} / ${CLIENT_NAME}` : CLIENT_NAME;
|
||||
}, [title, snapStates.currentLocation]);
|
||||
}, [title, matched]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue