[BUGFIX beta] Fix substates for nested routes and auto-generated index routes

Including refactoring to avoid duplication which felt responsible for the initial error.
Merge pull request #9308 from BookingSync/fix-substates

[BUGFIX beta] Fix substates for nested routes and auto-generated index routes