The BBC reports on a paper in the Royal Society journal Proceedings B by a group of zoologists from the University of British Columbia, Canada. These zoologists, lead by Clarice Fu, studied the development of gills in rainbow trout larvae. They found that the larval gills developed the ability to regulate blood chemicals significantly earlier than the ability to exchange oxygen. As fish mature, both their ion exchange, and the oxygen uptake shifts from being primarily localized to the skin, to being localized to the gills. By studying the ability of young rainbow trout gills to exchange ions and to take up oxygen, the zoologists found that the localization of the ion uptake shifted to the gills first.
Clarice Fu et al go on to use the developing larvae as a model of evolutionary pressures, therefore proposing that as the rainbow trout evolved, ion exchange moved to the gills before the animals started breathing through their gills.
The question remains: why did fish evolve gills in the first place? Ion exchange can only move to the gills if the structures are already in place and capable of supporting exchange.