Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this react route throwing an error of no route matched location?

I have some problem related to routing in my code im getting error "react_devtools_backend.js:4026 No routes matched location "/airlines/1/reviews/new" .That is when im trying to give a review to a particular airline.
here is my code
I have App.js-Airlines.js-AirlineCard.js-Reviews.js-AddReviewForm

App.js.My route is defined here

 const[reviews,setReviews]=useState([]); 
.
.
.

            <Routes>

          <Route exact  path="/airlines" element={<><Search search={search} onSearchChange={setSearch} /><Airlines  /></>} />
           
          <Route exact  path="/myprofile" element={<MyProfile />} />
          
       
          <Route exact  path="/airlines/:id" element={<Reviews reviews={reviews} setReviews={setReviews} />} />
           
          <Route path="/airlines/${id}/reviews/new" element={ <AddreviewForm />} />
        
          <Route exact path="/" element={<Home user={user}/>} />
        
        </Routes>
```[enter image description here][1]

Airlines.js

function Airlines(){
const[airlines,setAirlines]=useState([]);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

useEffect(()=>{
    fetch("/airlines")
    .then(res=>res.json())
    .then(airData=>{
      setAirlines(airData)
    })
  
   },[])
  

   
return(
    <>
    <h1>Airlines</h1>
   {airlines.map((airline)=>(
    <AirlinesCard key={airline.id} airline={airline}/>
   ))

   }
   
    </>
)

}

AirlineCard.js

function AirlinesCard({airline}){
const{id,name,image,slogan,wlink}=airline;
return(
<>

{name}

{slogan}

<Link to={/airlines/${id}}>Enter

Book your tickets now!

    </>
)

}

Reviews.js

function Reviews({reviews,setReviews}){

useEffect(()=>{
fetch("/reviews")
.then(res=>res.json())
.then(reviewData=>{
setReviews(reviewData)
})
},[])

function handleAddReviews(newReview){
console.log("in handle add review", newReview)
setReviews([…reviews,newReview]);

}

const {id}=useParams();

console.log(reviews)
 let filteredReviews=reviews.filter(review=>{

  
   return review.airline.id===parseInt(id)})
return(
    <>
    <h1>Reviews</h1>
   
    <Link  to="/airlines"><button>Go Back</button></Link>
    <Link to={`/airlines/${id}/reviews/new`}><button>Add a Review</button></Link>
    { filteredReviews.map((review)=>{

return (

);
})}

    </>
)

}

I have defined my link to go to add review form in the Reviews.js

thanks

here is the link
  [1]: https://i.stack.imgur.com/s6JMJ.png

>Solution :

Your route looks like it’s got a typo, should be

<Route path="/airlines/:id/reviews/new" element={ <AddreviewForm />} />

instead of

<Route path="/airlines/${id}/reviews/new" element={ <AddreviewForm />} />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading