Create Pages in Blitz.js

Khaled Garbaya
InstructorKhaled Garbaya

Share this video with your friends

Send Tweet
Published a year ago
Updated 10 months ago

In Blitz, a page is a React Component exported from a .js, .jsx, .ts, or .tsx file in a pages directory. Each page is associated with a route based on its file name.

Example: if you create a file under app/pages/post like below, it will be accessible at /about

const Post = () => {
  return (
      <h1>Hello World</h1>

export default Post

Unlike Next.js, you can have many pages/ folders nested inside app/. This way pages can be organized neatly, especially for larger projects.

Khaled Garbaya: [0:00] To add a new page to our Blitz app, let's go to pages folder, create a new file, call it about.tsx. In here, let's paste in some code. Hit Save. Now, when we go to our app and go to /about, we can see here our page created.

[0:25] You can also have nested pages inside of the pages folder, so let's create a new folder, call it posts. Inside of that, let's create a new file, call it post1.tsx. Let's take this code and call this post. Hit Save and go to our URL. Instead of about, let's do posts/post1. You can see here our page is displayed.