We have an apex:actionFunction like so:

<apex:actionFunction name="communityLogin" action="{!login}">
    <apex:inputHidden value="{!username}" id="usernameHidden"/>
    <apex:inputHidden value="{!password}" id="passwordHidden"/>

This calls a controller function:

public PageReference login(){
    String redirectPage = '/login-success';
    PageReference loginPage = Site.login(username, password, redirectPage); 
    if(loginPage != null){
        return loginPage;
        PageReference pageRef = ApexPages.currentPage();
        //pageRef.getParameters().put('invalidLogin', 'true');
        return pageRef;

Javascript code (inside Angular component, called by button click):

  this.loggingIn = true; // to show a spinner
  let usernameElem:any = document.getElementById(window.usernameHiddenId);
  let passwordElem:any = document.getElementById(window.passwordHiddenId);
  if(usernameElem && passwordElem){
    usernameElem.value = this.username.value;
    passwordElem.value = this.password.value;


What we're trying to do here is to keep the user on the same page if they couldn't log in. (The javascript client app then will notify the user in a polite manner).
However, this doesn't work.
It always navigates to the Community's designated index page.
I understand from the docs that setting pageRef.setRedirect(false) should prevent the apex:actionFunction from navigating.
But that doesn't happen. It always navigates away from the page.

1 Answer 1


The apex:actionFunction does not have a reRender attribute, so it is reloading the page. This appears like you're navigating because Angular has to reinitialize, so it appears as if you've navigated to another page, but it's simply reloading. Adding a reRender attribute to the apex:actionFunction will prevent this from happening.

  • Nope. It prevents default behavior, but doesn't stop the navigation. No reason why it should. That's a different form from the one in the VF page. That form (VF) has no button. Oct 19, 2020 at 17:13
  • @AvailableName Hmm. The only other thing that comes to mind is that your apex:actionFunction doesn't have a reRender attribute, but that should only cause it to reload the current page, not navigate elsewhere.
    – sfdcfox
    Oct 19, 2020 at 17:37
  • That was it. It was reloading the page. But we're using the Angular router to navigate within the same VF page. So reloading the same page just looked like it was navigating away. I feel like such a dunce. Oct 19, 2020 at 17:47
  • @AvailableName No worries, we've all been there.
    – sfdcfox
    Oct 19, 2020 at 17:51
  • You wanna change your answer? Oct 20, 2020 at 11:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .