How to avoid users to go back to page once login in yii2

I am using yii2 basic application template and hosted filees on my VPS server. In my application login page, when the user logs in successfully to account, he will be able to access the dashboard and all other rights he has been assigned.

Now the scenario is user logs in, then he sees his dashboard as first page. Now if he clicks on back button of the browser error message is displayed as below:

This page isn’t working
localhost redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

Even if he clicks on back button of the browser he should be redirected to same dashboard page.

How to accomplish this?

Here is my login action:

public function actionLogin()
    {
        $this->layout= "loginlayout";
        if (!Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {

              return $this->redirect("index.php?r=dashboard/index");
            }

        else
        return $this->render('login', [
            'model' => $model,
        ]);
    }

this kind of contradicts with

your VPS should not be localhost. Are you sure you are testing on the right system? Or maybe you have something hardcoded for localhost on your server?

The above should better be written as

return $this->redirect(['/dashboard/index']);

to use Yii url manager to build URLs. See https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing

I tried on first time, second time on localhost, it is working fine but third time if I click on Back button of browser then previous page is displayed which was before login page i,e. automatic it is getting logged out. It should not happen.

For example, if we log in to our Gmail account, first time we see our inbox. And now if we click on back button any time then only Inbox page is displayed. We are not getting logged out unless we click on Sign out button. I want to accomplish the same.

Here is my action login:

public function actionLogin()
    {
		$this->layout= "loginlayout";
        if (!Yii::$app->user->isGuest) {
            return $this->redirect(['/dashboard/index']);
        }
		
        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
			 
              return $this->redirect(['/dashboard/index']);
			}
        
		else
        return $this->render('login', [
            'model' => $model,
        ]);
    }

Here is my action index:

public function actionIndex()
    {
		
       return $this->redirect('index.php?r=site/login');
		$this->layout= "loginlayout";
    }

Here is my action logout:

public function actionLogout()
    {
       
		$this->layout= "loginlayout";
		Yii::$app->user->logout();
        return $this->goHome();
    }