From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Dynamic metadata

Dynamic metadata

All right, guys. So I just figured that a nice touch onto our search page or search results is to have the category or the query, whatever it is we're filtering, to have that in the title. And we can use this generate metadata function for dynamic metadata, where in most of our pages, we've been using just this metadata object. So the generate metadata can take in your params, meaning it can take in the search params from the props that we pass in. So our category, queries, thing like that. And we can use it in our title. So that's what I want to do. We're going to go to our search page. So app root search page TSX. And let's just go below the arrays we created. So we'll go below the sort orders. And we want to export an async function called generate metadata. For now, let's just return an object with the title, and we'll just say search for now. And for some reason, that takes a couple of reloads to kick in. OK, so now we have search. Now what I want to do is pass in here. So in the…

Contents