headstartwp icon indicating copy to clipboard operation
headstartwp copied to clipboard

update currentSite to match 404 and 500 pages

Open tobeycodes opened this issue 2 years ago • 6 comments

404 and 500 pages do not sit under the _sites/[site] middleware so do not have access to the query param. The site can be set here with the window.location.host value instead.

const currentSite = useMemo(() => {
	if (router.query?.site && !Array.isArray(router.query.site)) {
		return getSiteByHost(router.query.site, router.locale);
	}

	// 404.js and 500.js do not have a site query param.
	if (typeof window !== 'undefined') {
		return getSiteByHost(window.location.host, router.locale);
	}

	return {};
}, [router]);

tobeycodes avatar Nov 29 '22 14:11 tobeycodes