Merge pull request #405 from shishantbiswas/fix-sidebar-link-href
fix: sidebar links href to include `adminBasePath`
This commit is contained in:
@@ -16,6 +16,11 @@ export type BkndAdminConfig = {
|
|||||||
* @default `/`
|
* @default `/`
|
||||||
*/
|
*/
|
||||||
basepath?: string;
|
basepath?: string;
|
||||||
|
/**
|
||||||
|
* Sub-path for the Admin UI within the base path
|
||||||
|
* @default ``
|
||||||
|
*/
|
||||||
|
admin_basepath?: string;
|
||||||
/**
|
/**
|
||||||
* Path to return to when clicking the logo
|
* Path to return to when clicking the logo
|
||||||
* @default `/`
|
* @default `/`
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { type LinkProps, Link as WouterLink, useRouter } from "wouter";
|
import { type LinkProps, Link as WouterLink, useRouter } from "wouter";
|
||||||
import { useEvent } from "../../hooks/use-event";
|
import { useEvent } from "../../hooks/use-event";
|
||||||
|
import { useBkndOptions } from "ui/client/BkndProvider";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transforms `path` into its relative `base` version
|
* Transforms `path` into its relative `base` version
|
||||||
@@ -70,11 +71,13 @@ export function Link({
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const bkndOptions = useBkndOptions();
|
||||||
|
const adminBasePath = bkndOptions?.admin_basepath ?? "";
|
||||||
const _href = props.href ?? props.to;
|
const _href = props.href ?? props.to;
|
||||||
|
|
||||||
const href = router
|
const href = router
|
||||||
.hrefs(
|
.hrefs(
|
||||||
_href[0] === "~" ? _href.slice(1) : router.base + _href,
|
_href[0] === "~" ? adminBasePath + _href.slice(1) : router.base + _href,
|
||||||
router, // pass router as a second argument for convinience
|
router, // pass router as a second argument for convinience
|
||||||
)
|
)
|
||||||
.replace("//", "/");
|
.replace("//", "/");
|
||||||
@@ -82,8 +85,9 @@ export function Link({
|
|||||||
const active =
|
const active =
|
||||||
href.replace(router.base, "").length <= 1 ? href === absPath : isActive(absPath, href);
|
href.replace(router.base, "").length <= 1 ? href === absPath : isActive(absPath, href);
|
||||||
|
|
||||||
|
// console.log({ adminBasePath, _href, href, bkndOptions })
|
||||||
if (native) {
|
if (native) {
|
||||||
return <a className={`${active ? "active " : ""}${className}`} {...props} />;
|
return <a className={`${active ? "active " : ""}${className}`} {...props} href={href} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wouterOnClick = (e: any) => {
|
const wouterOnClick = (e: any) => {
|
||||||
@@ -99,10 +103,11 @@ export function Link({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
// @ts-expect-error className is not typed on WouterLink
|
||||||
<WouterLink
|
<WouterLink
|
||||||
// @ts-expect-error className is not typed on WouterLink
|
|
||||||
className={`${active ? "active " : ""}${className}`}
|
|
||||||
{...props}
|
{...props}
|
||||||
|
className={`${active ? "active " : ""}${className}`}
|
||||||
|
href={`~${href}`}
|
||||||
onClick={wouterOnClick}
|
onClick={wouterOnClick}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ export function useNavigate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const _url = options?.absolute ? `~/${basepath}${url}`.replace(/\/+/g, "/") : url;
|
const _url = options?.absolute ? `~/${app.options.basepath}/${app.options.admin_basepath}${url}`.replace(/\/+/g, "/") : url;
|
||||||
const state = {
|
const state = {
|
||||||
...options?.state,
|
...options?.state,
|
||||||
referrer: location,
|
referrer: location,
|
||||||
|
|||||||
Reference in New Issue
Block a user