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

Including refactoring to avoid duplication which felt responsible for the initial error.