I'm not sure I understood your question correctly (a more detailed description will be useful), but it seems that you can use the return statement as follows:
public PageReference method() {
if (some specific condition) {
return null;
}
PageReference pageRef = new PageReference('someURL');
return pageRef;
}
Please show your code for more help.
source
share