Single-photon switches and transistors generate strong photon-photon interactions that are essential for quantum circuits and networks. However, to deterministically control an optical signal with a single photon requires strong interactions with a quantum memory, which have been lacking in a solid-state platform. We realize a single-photon switch and transistor enabled by a solid-state quantum memory. Our device consists of a semiconductor spin qubit strongly coupled to a nanophotonic cavity. The spin qubit enables a single gate photon to switch a signal field containing up to an average of 27.7 photons, with a switching time of 63 ps. Our results show that semiconductor nanophotonic devices can produce strong and controlled photon-photon interactions that could enable high-bandwidth photonic quantum information processing.