• Ionic polymers can directly serve as high-performance ion-selective membranes when physically confined within submillimeter-sized cylindrical pores.
• The universality of this strategy is demonstrated in preparing cation/anion-selective membranes.
• With real seawater and river water, the output power density of a three-chamber cell representing a repeat unit of a reverse electrodialysis system can reach up to 8.99 W m−2.
• This work provides a new strategy for polyelectrolyte hydrogel-based ion-selective membranes with broad applications in osmotic energy collection, electrodialysis, and flow batteries.