Create your first Astro page
This content is not available in your language yet.
Now that you know that .astro
files are responsible for pages on your website, it’s time to create one!
Przygotuj się na…
- Create two new pages on your website: About and Blog
- Add navigation links to your pages
- Deploy an updated version of your website to the web
Create a new .astro
file
Section titled Create a new .astro file-
In the files pane of your code editor, navigate to the folder
src/pages/
where you will see the existing fileindex.astro
-
In that same folder, create a new file named
about.astro
. -
Copy, or retype the contents of
index.astro
into your newabout.astro
file.Your editor might show a solid white circle on the tab label for this file. This means that the file is not yet saved. Under the File menu in VS Code, enable “Auto Save” and you should no longer need to save any files manually.
-
Add
/about
to the end of your website preview’s URL in the address bar and check that you can see a page load there. (e.g.http://localhost:4321/about
)
Right now, your “About” page should look exactly the same as the first page, but we’re going to change that!
Edit your page
Section titled Edit your pageEdit the HTML content to make this page about you.
To change or add more content to your About page, add more HTML element tags containing content. You can copy and paste the HTML code below between the existing <body></body>
tags, or create your own.
Now, visit your /about
page in your browser tab again, and you should see your updated content.
Add navigation links
Section titled Add navigation linksTo make it easier to preview all your pages, add HTML page navigation links before your <h1>
at the top of both of your pages (index.astro
and about.astro
):
Check that you can click these links to move back and forth between pages on your site.
Unlike many frameworks, Astro uses standard HTML <a>
elements to navigate between pages (also called routes), with traditional page refreshes.
Try it yourself - Add a Blog page
Section titled Try it yourself - Add a Blog pageAdd a third page blog.astro
to your site, following the same steps as above.
(Don’t forget to add a third navigation link to every page.)
Show me the steps.
- Create a new file at
src/pages/blog.astro
. - Copy the entire contents of
index.astro
and paste them intoblog.astro
. - Add a third navigation link to the top of every page:
You should now have a website with three pages that all link to each other. It’s time to add some content to the Blog page.
Update the page content at blog.astro
with:
Preview your entire site by visiting all three pages in your browser preview and check that:
- Every page correctly links to all three pages
- Your two new pages each have their own descriptive heading
- Your two new pages each have their own paragraph text
Publish your changes to the web
Section titled Publish your changes to the webIf you’ve followed our setup in Unit 1, you can publish your changes to your live website through Netlify.
When you are happy with the way your preview looks, commit your changes to your online repository at GitHub.
-
In VS Code, preview the files that have changed since your last commit to GitHub.
-
Go to the Source Control tab in the left menu. It should have a small “3” displayed.
-
You should see
index.astro
,about.astro
, andblog.astro
listed as files that have changed.
-
-
Enter a commit message (e.g. “Added two new pages - about and blog”) in the text box, and press Ctrl + Enter (macOS: Cmd ⌘ + Enter) to commit the change to your current workspace.
-
Click the button to Sync Changes to GitHub.
-
After waiting a few minutes, visit your Netlify URL to verify that your changes are published live.
Follow these steps every time you pause working! Your changes will be updated in your GitHub repository. If you’ve deployed to a Netlify website, it will be rebuilt and republished.