Verified Commit a09d9fd0 authored by Jakob Moser's avatar Jakob Moser
Browse files

Improve current page detection

parent cd53aa35
Loading
Loading
Loading
Loading
Loading
+13 −0
Changes for portal/static/js/components/pieces/Nav.mjs: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,19 @@ export const Nav = {
                    ),
                ]),
            ),
            m(
                "section.right",
                m("ul", [
                    m(
                        "li",
                        m(NavPageLink, {
                            href: `/login?next=${m.route.get() || "/"}`,
                            label: " Anmelden",
                            icon: "fa-regular fa-user",
                        }),
                    ),
                ]),
            ),
        ])
    },
}
+10 −7
Changes for portal/static/js/components/pieces/NavPageLink.mjs: 10 added lines, 7 removed lines.
Original line number Diff line number Diff line
export const NavPageLink = {
    view(vnode) {
        const href = vnode.attrs.href
        const currentRoute = m.route.get()
        const isCurrent =
            currentRoute === href || (currentRoute === "" && href === "/")
        // See https://mithril.js.org/parsePathname.html
        const currentPath = m.parsePathname(m.route.get()).path
        const isCurrent = currentPath === m.parsePathname(href).path

        return m(
            m.route.Link,
            { href, class: isCurrent ? "current" : "" },
        return m(m.route.Link, { href, class: isCurrent ? "current" : null }, [
            vnode.attrs.icon
                ? m("i", {
                      class: vnode.attrs.icon,
                  })
                : null,
            vnode.attrs.label,
        )
        ])
    },
}