It's all chemoception, the same as with single cell organisms. They swim towards a saline gradient ( which they can taste, for sure ) and follow it up into fresher and fresher water.