Categories

Sunday, September 26, 2021
therichposts@gmail.com
Next.jsReactjs

Dynamic linking routes in Next.js

Dynamic linking routes in Next.js

Hello friends, welcome back to my blog and today in this blog post, I am going to show you, Dynamic linking routes in Next.js.

Next. js is a JavaScript framework created by Zeit. With this we can build server-side rendering and static web applications using React.

Friends here is the working code snippet for Dynamic linking routes in Next.js and please use this carefully:


1. Very first guys, I will tell you, how to add dynamic links inside the loop in Next.js:

In this example, I am getting the product info in loop and set dynamic routing links according to ID and guys route will be link : https://yourside.com/product/9341

...
import Link from 'next/link';
class App extends Component {

     //Store Dynamic data
     constructor(props) {
        super(props)
          this.state = {
            data: []
                  }
          }
render() {
   return (
    <div>
       {this.state.data.map((result) => {
            return (

                        <div>
                         
                           <Link
                              href={`/product?${result.id}`}
                              as={`product/${result.id}`}>
                              <a className="ps-collection">{result.title}</a>
                            </Link>

                        </div>
               )
            })}
     </div>
)
}
}

export default App;

 

Now we are done friends also and If you have any kind of query or suggestion or any requirement then feel free to comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.

Jassa

Thanks

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.