Skip to content

Commit 4fc0143

Browse files
pushing notes and content about custom 404 pages
1 parent 16b42b0 commit 4fc0143

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ It is the best tutorial series on Next.js by far and is over 70 videos long.
1515
- Navigating Programmatically
1616
- Custom 404 Pages
1717
- Pre-rendering and Data Fetching
18+
- Types of Pre-Rendering
19+
- Static Generation
20+
- with and without data
21+
- Incremental Static Generation
22+
- Dynamic Paramters when fetching data
23+
- Server-side Rendering
24+
- Data fetching
25+
- Client-side Data Fetching
26+
- Combining pre-rendering with client-side data fetching
1827
- Static Generation
1928
- Static Generation with g etStaticProps
2029
- Pages vs Components

notes/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Supplemental Notes
2+
3+
## Notes that don't belong in the code
4+
5+
### Difference between rendering methods in React and Next
6+
7+
By default, Next JS pre-renders every page in the application. This means that it generates HTML for each page in advance insead of having it all done by client-side JavaScript
8+
9+
In a React app, the JavaScript is loaded which then executes to load the HTMl elements onto the DOM. We just have a div tag with Id tag equal to root. Once the javascript for the page is loaded, it will exceute in the browser, create the different DOM nodes and mount them onto the root div element. This process is called Hydration.
10+
11+
In a Next app, the pages are pre-rendered automatically by default, meaning the HTML is already generated with the necessary data and then sent to the browser. The JS then loads and makes the page interactive.
12+
13+
#### Why pre-render?
14+
15+
1. Pre-rendering improves performance
16+
1. In a react app, you need to wait for the JavaScript to be executed
17+
2. Perhaps fetch data from an external API and then render the UI
18+
3. There is a lag time for the user
19+
4. With a pre-rendered page, the HTMl is already generated and loads faster
20+
2. Pre-rendering helps with SEO
21+
1. This isn't as big of an issue with sites that are built behind a login screen, but if you're building a blog or an e-commerce site, then SEO is a concern.
22+
2. With a react app, if the search engine hits your page, it only sees a div tag with id equal to root.
23+
3. If search engines hit a pre-rendered page, all the content is present in the source code which will help with crawlers that are indexing the page.
24+
4. If SEO is of concern for app, then pre-rendering is what you want
25+
26+
#### How do you pre-render?

pages/404.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// To create a custom 404 page, all you have to do is create a 404.js file in the pages folder. The file name has to be 404.js and nothing else.
2+
3+
// define a component
4+
5+
function PageNotFound() {
6+
return <h1>404 Page with all the custom styling necessary</h1>
7+
}
8+
9+
export default PageNotFound
10+
11+
// not worried about styling the page at the moment.... just trying to get an understanding on how to define the custom 404 page.

pages/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import Link from 'next/link'
2+
import { useRouter } from 'next/router'
23

34
function Home() {
5+
const router = useRouter()
6+
7+
const handleClick = () => {
8+
console.log('Placing your order')
9+
router.push('/product')
10+
}
411
return (
512
<>
613
<h1>Home Page</h1>
@@ -10,8 +17,41 @@ function Home() {
1017
<Link href='/product'>
1118
<a>Products</a>
1219
</Link>
20+
<button onClick={handleClick}>Place Order</button>
1321
</>
1422
)
1523
}
1624

1725
export default Home
26+
27+
/*
28+
29+
### Routing Summary
30+
31+
Next.js uses a file based routing system.
32+
33+
- Page Based Routing System - Pages are associated with a route based on their file name.
34+
35+
- Nested Routes are a nested folder structure where files will be automatically routed in the same way in the URL.
36+
37+
- Dynamic Routes can be created by adding square brackets to a page name.
38+
39+
- Catch All Routes - add three dots (like a spread operator) inside square brackets to create a catch all route. They're helpful if you want different URLs for the same page layout or even when you're working with pages where some of the route parameters are optional.
40+
41+
To navigate to other routes (pages), we wrap the heading for those pages in a Link (capital 'L') component and have the href point to the corresponding internal page via '/PAGE'
42+
43+
Place Order Button: first, we add the button and give it a click handler. Next, we define the handler through a const. Within, the order body, we're assuming the order was placed successfully and log 'placing your order'. Then, the user should be programmatically navigated to the products page.
44+
45+
To do this, at the top, we import useRouter from next/router.
46+
47+
Within the component, we make const router = useRouter. Within this object, we can access the push method, passing in the route as the argument.
48+
49+
In this example, we're navigating to /product. So, we import next/router and define a router const.
50+
51+
We're currenly only trying to navigate back to the product argument, but we can navigate to nested routes, dynamic routes, and catch-all routes.
52+
53+
If you want to replace the history instead of pushing the route onto the stack, you can use router.replace. The behavior is similar ot the link component with the prop set to True.
54+
55+
Remember - you use the 'useRouter' hook's _router.push_ method to navigate programmatically
56+
57+
*/

0 commit comments

Comments
 (0)