Skip to content
Advertisement

How do I create multiple pages within my domain using React?

When a user goes to my domain www.example.com they see my webpage I created using React. I want to use React to show them a different webpage when they go to www.example.com/anotherpage instead.

This is the code I have in my index.js file which creates the webpage at www.example.com,

JavaScript

Advertisement

Answer

There are multiple solution for this, if you are creating an SPA with create-react-app, then one of the most popular solution is by using react-router.

As shown in the example, then the basic routing is like this:

JavaScript

However if you are using another framework such as Next.js, then they have the filesystem pages where creating a page under /pages/ folder will create a new route.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement