Well there's a command named
\autopageref{} which replaces \pageref{} and does exactly what I wanted. More info here.\autopageref{} which replaces \pageref{} and does exactly what I wanted. More info here.\section*{foo}
\label{sec:foo}
...
\nameref{sec:foo}