Skip to content

Commit e9d6699

Browse files
committed
Add support for external links in SidebarNav component
1 parent dbca5e2 commit e9d6699

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

src/AppRouter.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ const AppRouter: React.FC = () => {
3333
component={Administration}
3434
layout={DashboardLayout}
3535
/>
36+
<RouteWithLayout
37+
path={`/account`}
38+
component={() => null}
39+
layout={DashboardLayout}
40+
/>
41+
<RouteWithLayout
42+
path={`/settings`}
43+
component={() => null}
44+
layout={DashboardLayout}
45+
/>
3646
</Switch>
3747
</AppRouterComponent>
3848
)

src/_common/AppSidebar/SidebarNavRecursive/NavItemComponent.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,50 @@ import { makeStyles, createStyles } from '@material-ui/core/styles'
66

77
import { NavLink, NavLinkProps } from 'react-router-dom'
88

9-
export const NavItemLink = forwardRef<HTMLAnchorElement, NavLinkProps>((props, ref) => (
10-
<NavLink exact {...props} innerRef={ref} />
11-
))
12-
13-
export interface INavItemComponent {
9+
type NavItemComponentProps = {
1410
link?: string
1511
className?: string
1612
isCollapsed?: boolean
1713
style?: any
1814
onClick(e: MouseEvent): void
1915
}
2016

17+
interface NavItemLinkInternalProps extends NavLinkProps {}
18+
19+
export const NavItemLinkInternal = forwardRef<
20+
HTMLAnchorElement,
21+
NavItemLinkInternalProps
22+
>((props, ref) => {
23+
return <NavLink exact {...props} innerRef={ref} />
24+
})
25+
26+
export const NavItemLinkExternal = forwardRef<HTMLAnchorElement, NavItemComponentProps>(
27+
(props, ref) => {
28+
return (
29+
<a {...props} href={props.link} ref={ref}>
30+
{props.children}
31+
</a>
32+
)
33+
},
34+
)
35+
2136
// Can be a link, or button
2237
export const NavItemComponent = forwardRef<
2338
HTMLDivElement,
24-
React.PropsWithChildren<INavItemComponent>
39+
React.PropsWithChildren<NavItemComponentProps>
2540
>((props, ref) => {
2641
const { isCollapsed, ...newProps } = props
2742
const classes = useStyles()
2843

29-
const component =
30-
typeof props.link === 'string' ? (
31-
<ListItem {...newProps} component={NavItemLink} to={props.link} />
32-
) : (
33-
<ListItem {...newProps} button />
34-
)
44+
const component = (() => {
45+
if (!props.link) {
46+
return <ListItem {...newProps} button />
47+
} else if (typeof props.link === 'string' && !props.link.includes('http')) {
48+
return <ListItem {...newProps} component={NavItemLinkInternal} to={props.link} />
49+
} else if (typeof props.link === 'string' && props.link.includes('http')) {
50+
return <ListItem {...newProps} component={NavItemLinkExternal} />
51+
}
52+
})()
3553

3654
return (
3755
<div ref={ref} className={clsx(isCollapsed && classes.navItemCollapsedWrapper)}>

src/_common/AppSidebar/SidebarNavRecursive/SidebarNav.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ const SidebarNav: React.FC<ISidebarNavProps> = (props) => {
6565
items: [
6666
{
6767
name: 'Profile',
68-
link: '/profile/me',
68+
link: '/account/profile',
6969
},
7070
{
7171
name: 'Organization',
72-
link: '/organization',
72+
link: '/account/organization',
7373
},
7474
],
7575
},
@@ -92,15 +92,15 @@ const SidebarNav: React.FC<ISidebarNavProps> = (props) => {
9292
]
9393

9494
const itemsTheme = [
95-
{
96-
name: 'Why Modular?',
97-
link: '/demo/features',
98-
Icon: IconNewReleases,
99-
IconClassName: classes.iconFeatures,
100-
},
95+
// {
96+
// name: 'Why Modular?',
97+
// link: '/demo/features',
98+
// Icon: IconNewReleases,
99+
// IconClassName: classes.iconFeatures,
100+
// },
101101
{
102102
name: 'Docs',
103-
link: '/demo/docs',
103+
link: 'https://github.com/modularcode/modular-admin-react/blob/master/README.md',
104104
Icon: IconLibraryBooks,
105105
IconClassName: classes.iconDocs,
106106
},

0 commit comments

Comments
 (0)