Every fungus gnat egg, larva and pupa is in the compost. Replacing the compost removes them all at once, which is why repotting is the most complete single measure available.
When it is worth doing
When an infestation has persisted through six to eight weeks of surface drying and other measures. When the compost is old and degraded anyway, so the repot was due. When the plant is small enough that the disruption is minor. And when the compost has clearly become the problem – sour, dense, permanently wet.
It is not worth doing as a first response, since it costs the plant a setback and the same result is usually available without it.
How to do it for this purpose
The approach differs from a routine repot, because the aim is removal rather than refreshment.
Remove as much old compost from the roots as you reasonably can – more than you would normally – and in a bad case wash the roots clean. Dispose of the old compost in the bin rather than on a garden, and do it outside if possible.
Clean the pot thoroughly, since pupae can be present in the residue around the rim and drainage holes.
Use fresh compost from a sealed bag, ideally with a high proportion of perlite so the surface dries quickly, and apply a grit top-dressing immediately.
The timing problem
Repotting is best done in spring, and infestations do not respect that. A serious problem in November presents a genuine conflict.
Where the plant is otherwise healthy and the infestation is tolerable, waiting until spring and managing with drying and biological control in the meantime is usually the better choice.
Where larvae are damaging the roots of a small plant or a cutting, repotting immediately is justified despite the season.
Doing the whole collection
Repotting one plant while its neighbours remain infested achieves little, since adults simply recolonise. If repotting is the chosen route in a collection-wide problem, it needs to be done across all affected pots within a short period.
That is a substantial undertaking, which is another argument for the less disruptive measures first.
Afterwards
Treat the repotted plant as any other – reduced watering, no feeding for six to eight weeks, bright indirect light. Keep a sticky trap in place to confirm the problem has gone rather than assuming.
And adjust the watering permanently, since a repot into fresh compost with the old routine will simply produce a new population within a couple of months.