Dynamic route matching
If you are tasked to build a simple portfolio site, basic routes are going to be just fine. However, as you start to work on more complex sites such as blogs, you will need more complex routing. In this section, we are going to learn about dynamic route matching. Dynamic route matching is used to define routes that require one or more parameters to be dynamic.
All the routes that we have defined until now were static and did not change. So, we had the /about
endpoint that would render the About page and the /
path that would welcome the home page of our site. What would happen if we wanted to develop a blog post with our current knowledge? After our first blog post, we would write a route, /blog/1
, then after the second, we would have to create another route, /blog/2
, and so on.
Defining routes statically like this is not an ideal solution, and this is where dynamic route matching comes into place. Dynamic route matching allows us to create a pattern, for...