Cannot set property 'forwardViewId' of undefined

I too have encountered the same issue. My scenario is as follows:
Whenever you try to access a page and you’re not authenticated, the app redirects to the login screen. Once the user logs in, the app redirects to a default screen. The moment the user hits the login button the same “forwardViewId” error is shown.

I have found that this code is causing the problem:

It is rather curious to see that the counter x starts from 0 and yet it is being used as an array index with the value x - 1.