ปัญหาหลักของการตอบสนองการรับเส้นทางปัจจุบันคืออาจช้า
There is no built-in way to get the current route in React. However, you can use the router's context to get the current location, which will give you the current pathname. const { location } = this.context.router; console.log(location.pathname); // /some/path
ชื่อ
ใช้ตำแหน่ง () ตะขอ
ตะขอ uselocation() ใช้เพื่อกำหนดว่าส่วนประกอบควรแสดงผลที่รูทหรือไม่ หากส่วนประกอบไม่ควรแสดงผลที่รูท สามารถใช้ hook นี้เพื่อกำหนดตำแหน่งที่ควรแสดงผลแทน
วิธีรับเส้นทาง
มีสองสามวิธีในการรับเส้นทางใน React วิธีหนึ่งคือใช้ react-router อีกวิธีคือใช้ react-router-dom