pathFor fix for optional segments. See #338