components#Nav JavaScript Examples
The following examples show how to use
components#Nav.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _app.js From next-js-10-crud-example with MIT License | 6 votes |
function App({ Component, pageProps }) {
return (
<>
<Head>
<title>Next.js 10 - CRUD Example with React Hook Form</title>
{/* bootstrap css */}
<link href="//netdna.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
</Head>
<div className="app-container bg-light">
<Nav />
<Alert />
<div className="container pt-4 pb-4">
<Component {...pageProps} />
</div>
</div>
{/* credits */}
<div className="text-center mt-4">
<p>
<a href="https://jasonwatmore.com/post/2021/04/20/next-js-10-crud-example-with-react-hook-form" target="_top">Next.js 10 - CRUD Example with React Hook Form</a>
</p>
<p>
<a href="https://jasonwatmore.com" target="_top">JasonWatmore.com</a>
</p>
</div>
</>
);
}
Example #2
Source File: _app.js From next-js-11-basic-authentication-example with MIT License | 6 votes |
function App({ Component, pageProps }) {
return (
<>
<Head>
<title>Next.js 11 - Basic HTTP Authentication Example</title>
{/* eslint-disable-next-line @next/next/no-css-tags */}
<link href="//netdna.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
</Head>
<div className="app-container bg-light">
<Nav />
<div className="container pt-4 pb-4">
<RouteGuard>
<Component {...pageProps} />
</RouteGuard>
</div>
</div>
{/* credits */}
<div className="text-center mt-4">
<p>
<a href="https://jasonwatmore.com/post/2021/08/29/next-js-basic-http-authentication-tutorial-with-example-app" target="_top">Next.js 11 - Basic Authentication Tutorial with Example App</a>
</p>
<p>
<a href="https://jasonwatmore.com" target="_top">JasonWatmore.com</a>
</p>
</div>
</>
);
}
Example #3
Source File: _app.js From next-js-11-jwt-authentication-example with MIT License | 5 votes |
function App({ Component, pageProps }) {
const router = useRouter();
const [authorized, setAuthorized] = useState(false);
useEffect(() => {
// run auth check on initial load
authCheck(router.asPath);
// set authorized to false to hide page content while changing routes
const hideContent = () => setAuthorized(false);
router.events.on('routeChangeStart', hideContent);
// run auth check on route change
router.events.on('routeChangeComplete', authCheck)
// unsubscribe from events in useEffect return function
return () => {
router.events.off('routeChangeStart', hideContent);
router.events.off('routeChangeComplete', authCheck);
}
}, []);
function authCheck(url) {
// redirect to login page if accessing a private page and not logged in
const publicPaths = ['/login'];
const path = url.split('?')[0];
if (!userService.userValue && !publicPaths.includes(path)) {
setAuthorized(false);
router.push({
pathname: '/login',
query: { returnUrl: router.asPath }
});
} else {
setAuthorized(true);
}
}
return (
<>
<Head>
<title>Next.js 11 - JWT Authentication Example</title>
{/* bootstrap css */}
<link href="//netdna.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
</Head>
<div className="app-container bg-light">
<Nav />
<div className="container pt-4 pb-4">
{authorized &&
<Component {...pageProps} />
}
</div>
</div>
{/* credits */}
<div className="text-center mt-4">
<p>
<a href="https://jasonwatmore.com/post/2021/08/04/next-js-11-jwt-authentication-tutorial-with-example-app" target="_top">Next.js 11 - JWT Authentication Tutorial with Example App</a>
</p>
<p>
<a href="https://jasonwatmore.com" target="_top">JasonWatmore.com</a>
</p>
</div>
</>
);
}
Example #4
Source File: _app.js From next-js-11-registration-login-example with MIT License | 5 votes |
function App({ Component, pageProps }) {
const router = useRouter();
const [user, setUser] = useState(null);
const [authorized, setAuthorized] = useState(false);
useEffect(() => {
// on initial load - run auth check
authCheck(router.asPath);
// on route change start - hide page content by setting authorized to false
const hideContent = () => setAuthorized(false);
router.events.on('routeChangeStart', hideContent);
// on route change complete - run auth check
router.events.on('routeChangeComplete', authCheck)
// unsubscribe from events in useEffect return function
return () => {
router.events.off('routeChangeStart', hideContent);
router.events.off('routeChangeComplete', authCheck);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
function authCheck(url) {
// redirect to login page if accessing a private page and not logged in
setUser(userService.userValue);
const publicPaths = ['/account/login', '/account/register'];
const path = url.split('?')[0];
if (!userService.userValue && !publicPaths.includes(path)) {
setAuthorized(false);
router.push({
pathname: '/account/login',
query: { returnUrl: router.asPath }
});
} else {
setAuthorized(true);
}
}
return (
<>
<Head>
<title>Next.js 11 - User Registration and Login Example</title>
{/* eslint-disable-next-line @next/next/no-css-tags */}
<link href="//netdna.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
</Head>
<div className={`app-container ${user ? 'bg-light' : ''}`}>
<Nav />
<Alert />
{authorized &&
<Component {...pageProps} />
}
</div>
{/* credits */}
<div className="text-center mt-4">
<p>
<a href="https://jasonwatmore.com/post/2021/08/19/next-js-11-user-registration-and-login-tutorial-with-example-app" target="_top">Next.js 11 - User Registration and Login Tutorial with Example App</a>
</p>
<p>
<a href="https://jasonwatmore.com" target="_top">JasonWatmore.com</a>
</p>
</div>
</>
);
}