ASPNetCore/Next/pages/shared/Layout.tsx

82 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2021-03-25 10:07:27 +00:00
import React from 'react'
import Head from 'next/head'
import Link from 'next/link'
import { useRouter } from 'next/router'
import 'bootstrap/dist/css/bootstrap.min.css'
const NavLink: React.FunctionComponent<{href: string}> = ({href, children}) => {
const router = useRouter();
const NavLinkClasses = (active) => {
if(active) {
return "nav-link active";
} else {
return "nav-link"
}
}
const NavLinkCurrent = (active) => {
if(active) {
return "page";
} else {
2021-03-29 07:40:58 +00:00
return undefined;
2021-03-25 10:07:27 +00:00
}
}
const active = router.pathname == href;
return (
<li className='nav-item active'>
<Link href={href}>
2021-03-29 07:40:58 +00:00
<a className={NavLinkClasses(active)} aria-current={NavLinkCurrent(active)}>{children}</a>
2021-03-25 10:07:27 +00:00
</Link>
</li>
);
}
const NavBar: React.FunctionComponent<{}> = () => {
return (
<nav className='navbar navbar-expand-lg navbar-light bg-light'>
<a className='navbar-brand' href='#'>
Navbar
</a>
<button
className='navbar-toggler'
type='button'
data-toggle='collapse'
data-target='#navbarSupportedContent'
aria-controls='navbarSupportedContent'
aria-expanded='false'
aria-label='Toggle navigation'
>
<span className='navbar-toggler-icon' />
</button>
<div className='collapse navbar-collapse' id='navbarSupportedContent'>
<ul className='navbar-nav mr-auto'>
<NavLink href="/">Home</NavLink>
<NavLink href="/todo">Todo</NavLink>
2021-03-29 07:40:58 +00:00
<NavLink href="/customer">Customer</NavLink>
<NavLink href="/product">Product</NavLink>
2021-03-25 10:07:27 +00:00
</ul>
</div>
</nav>
)
}
export class Layout extends React.Component<{
title: string
}> {
render () {
return (
<div>
<Head>
<meta name='viewport' content='width=device-width, initial-scale=1' />
<title>{this.props.title} - TestAppRuna</title>
</Head>
<header>
<NavBar />
</header>
<main>{this.props.children}</main>
<footer></footer>
</div>
)
}
}