On-demand ridesharing has been recognised as an effective way to meet travel needs while significantly reducing the number of required vehicles. As the growth of on-demand mobility services and the advent of shared autonomous vehicles are envisioned to boost the presence of ridesharing vehicles, these may soon significantly affect traffic patterns in our cities. However, most previous studies investigating dynamic ridesharing systems overlook the effects on travel times due to the assignment of requests to vehicles and their routes. In order to assign the ridesharing vehicles while considering network traffic dynamics, we propose a strategy that incorporates time-dependent link travel time predictions into the request–vehicle assignment to avoid or mitigate traffic congestion. In particular, we formulate an efficient linear assignment problem that considers multiple path alternatives and accounts for the impact on travel times, which may be potentially caused by vehicles assigned to specific routes. Simulation experiments reveal that using an appropriate congestion avoidance ridesharing strategy can remarkably reduce passenger average travel and waiting times by alleviating endogenous congestion caused by ridesharing fleets.