Near-field control and switching of an optical signal