The first pull request for Release0.3

 For the first pull request of Release0.3, I choose a new project named react-course-theme to deal with. 

In the project, there is a crash issue when the user input a url to enter the website directly. But it will be fine if the user enter the website through the link of the main page.

Error message


When I analyze the project, I find the problem comes from using useLocation() function of "react-router-dom". When every route is connected, the value can be passed from one page to the next clicked page. But when you want to enter the website directly through URL, the new page can't get the value from the useLocation() function.

                                     Use useLocation() function to get value from previous page


Pass value through history.push() function



In order to fix the issue, I choose to parse the URL to get unique ID using useParams() function of "react-router-dom". Then I fetch the data from source data using find() function.

                                                              Fixed code



After modifying the code, I run the project again and the website looks well. Then I pull the request in GitHub.

                                                     Normal output page


I didn't use the "useLocation()" and "useParams()" function of "react-router-dom" before. Through this project I search for the related material and learn how to use these feature. It was a very good experiment for me.












Comments

Popular posts from this blog

Choose a project in Release 0.4

Open source development course

Publish project in Lab 9