Nanoporous frameworks are polymeric materials built from rigid molecules, which give rise to their nanoporous structures with applications in gas sorption and storage, catalysis and others. Conceptually new applications could emerge, should these beneficial properties be manipulated by external stimuli in a reversible manner. One approach to render nanoporous frameworks responsive to external signals would be to immobilize molecular switches within their nanopores. Although the majority of molecular switches require conformational freedom to isomerize, and switching in the solid state is prohibited, the nanopores may provide enough room for the switches to efficiently isomerize. Here we describe two families of nanoporous materials incorporating the spiropyran molecular switch. These materials exhibit a variety of interesting properties, including reversible photochromism and acidochromism under solventfree conditions, light-controlled capture and release of metal ions, as well reversible chromism induced by solvation/desolvation.