Page Navigation

Welcome back! In this fifth lesson you will learn how to work with page navigation and how to pass data between pages.

In the last lesson you built a clickable Card Item component. Let's make it lead to a dedicated details page.

 

Key elements of a navigation system

Key elements of a navigation system

All Noodl projects start with a simple navigation system in place. In previous lessons we went through the basics of navigation. Let's refresh the memory of what is needed for navigation in Noodl:

  1. Multiple page components that each contain a page of your app. In this project you already have a Start Page and a Task Page.

  2. A Page Router node, that works as a container that controls which page component to show. This node is often placed in the App component.

  3. A Navigate node that lets you navigate from one page to another.

 

Page Router node

Page Router node

The Page Router node is a visual node that acts as a container for pages. Any page you navigate to will be rendered inside the Page Router and fill out the space available.

In the node graph, the Page Router often lives in between a Header and a Footer component. This way they don't need to be inserted (and rerendered) on every page.

If we select the Page Router you can see all the pages that are part of it. You can also set which page you want to act as the start page.

 

Creating pages

Creating pages

When you create a new page component it automatically gets added to the Page Router. A quick way to create a new page is by opening the Component Panel, then clicking the plus icon and picking page component.

It's time for you to create your very own page!

 

Lesson tasks

Time to get your hands dirty!

During this lesson, you will be given multiple tasks. Spot them in the lesson timeline by the Task label.

If you get stuck you can get a hint by clicking the card in the timeline.

Some of the nodes graphs will already be set up for you beforehand. This is to keep the lessons short so that you can focus on learning one concept at a time. If it feels like magic at times, don't worry. It's just a concept you will learn in a later lesson.

Task

Create a new page called Details Page

Open the Component Panel and click the plus icon in the Components section. Name it Details Page, remember that page names are case sensitive.

Task

Select the /details-page path in the Path Dropdown

 

Page components

The page component

Every page component comes with a Page node and a Page Inputs node. All children to the page node gets rendered on the page.

With the Page Inputs node, we can create Path and Query Inputs. They are used to send data into a page. You have probably seen this on other websites before, looking something like this: www.webshop.com/products?search=noodles.

We will take a closer look at this shortly, but first lets get a simple interface on this page.

 

Here's something we prepared earlier...

Here's something we prepared earlier...

To keep this lesson within a reasonable length we decided to add a component to the project containing a simple UI for our newly created Details Page.

You can go the Details Page Content component and copy all the nodes and paste them into the Details Page as children to the Page node.

Task

Copy all the nodes from the Details page content component, open the Details Page node graph and paste them under the Page node

Copy with Cmd/Ctrl + C and paste with Cmd/Ctrl + V

 

Page inputs

Page inputs

The Page Inputs node is similar to the Components Inputs node. It allows you to create parameters that can be used to send data into a page when you navigate to it.

There are two different types of parameters: query parameters and path parameters. In this lesson you will be using the latter.

The page parameters makes it possible to use a page component as a template, allowing you to keep the style and structure, but dynamically change the content.

Task

On the Page Inputs node, create a path parameter called Task id

Open the node graph for the Details Page. The name is case sensitive

Task

Create an Object node close to the Page Inputs node

Task

Connect the Page Inputs node to the Object node and send the task id output to the id input

Task

Go back to the Task Page node graph and delete the Object node

Task

Open the Node Picker and place a Navigate node close to the Repeater node

Task

On the Navigate node, set the target page property to Details Page

Task

Connect the Repeater node to the Navigate node and send the clicked output to the navigate input

Task

Connect the Repeater node to the Navigate node and send the item id output to the task id input

 

Object Id as a page parameter

Object Id as a page parameter

You now have a navigation system that allows us to click on a card, get its underlying object id, and use that as a path parameter when you navigate to the Details Page.

This allows you to access all the data via the Object in the Details Page component.

 

Object properties

Object properties

When there is a valid id set on a Object node, you can see all the available data when the node is inspected. However, to make it available as outputs, you need to manually create them as parameters by matching the names.

Task

In the Details Page node graph, add the following properties to the Object node: Image, Background Color, Title, Category, Date

Remember that property names are case sensitive

Task

Connect the Object node to the Hero section Group and send the background color output to the background color input

Task

Connect the Object node to the Image node and send the image output to the source input

Task

Connect the Object node to the Title Text node and send the title output to the text input

Task

Connect the Object node to the Text node inside the Category Group, and send the category output to the text input

Task

Connect the Object node to the Text node inside the Calender Group, and send the date output to the text input

 

Navigating back

Navigating back

You will now be navigated to the Details Page when you click a card. But what if you want to navigate back again?

The easiest way is just to use the back and forward controls built in to your browser. The Noodl editor has similar controls next to the Path Dropdown.

If you want to be fancy, you can use the Navigate node to create a custom back control. Let's do that.

Task

In the Details Page node graph, add a Navigate node and set the target page to Task Page

Task

Connect the Back Button node to the Navigate node and the click output to the navigate input

Task

Click the button to navigate back to the Task Page

Outro

Congratulations!

Congratulations!

You've completed the fifth tutorial! Hope you had fun.

Feel free to navigate back and forth to the details of each card if you have nothing better to do.

Otherwise, it seems about time to start building your own app!

Happy Noodling!