Let's give our users something to look at besides the (awesome) Redwood welcome page (thanks @alicelovescake!). We'll use the
redwood command line tool to create a page for us:
The command above does four things:
web/src/pages/HomePage/HomePage.js. Redwood takes the name you specified as the first argument after
pageand PascalCases it, then appends "Page" to construct your new page component. So "home" becomes "HomePage".
- Creates a test file to go along with this new page component at
web/src/pages/HomePage/HomePage.test.jswith a single, passing test. You do write tests for your components, don't you??
- Creates a Storybook file for this component at
web/src/pages/HomePage/HomePage.stories.js. Storybook is a wonderful tool for efficiently developing and organizing UI components. (If you want to take a peek ahead, we learn about Storybook in Part 2 of the tutorial).
- Adds a
web/src/Routes.jsthat maps the path
/to the new HomePage page.
Automatic import of pages in Routes file
If you look in Routes you'll notice that we're referencing a component,
HomePage, that isn't imported anywhere. Redwood automatically imports all pages in the Routes file since we're going to need to reference them all anyway. It saves a potentially huge
importdeclaration from cluttering up the routes file.
In case you didn't notice, this page is already live (your browser automatically reloaded):
It's not pretty, but it's a start! Open the page in your editor, change some text and save. Your browser should reload with your new text.
web/src/Routes.js and take a look at the route that was created:
Try changing the route to something like:
As soon as you add your first route, you'll never see the initial Redwood splash screen again. From now on, when no route can be found that matches the requested URL, Redwood will render the
NotFoundPage. Change your URL to http://localhost:8910/hello and you should see the homepage again.
Change the route path back to
/ before continuing!
Previous versions of this tutorial had you build everything without any styling, so we could really focus on the code, but let's face it: an unstyled site is pretty ugly. Let's add a really simple stylesheet that will just make things a little easier on the eyes as we build out the site. Paste the following into
These styles will switch to whatever your OS's system font is, put a little margin between things, and just generally clean things up. Feel free to tweak it to your liking (or ignore these styles completely and stick with the browser default) but keep in mind that the following screenshots are made against this base stylesheet so your experience may vary.
Looking better already!