State specific rules and redirects

Is it possible in Angular UI to have a rule which could lead to a redirect from one state to another before resolving and loading a states controller?

Lets say I have the following:

$stateProvider.state('questions', {
    url: '/questions/',
    resolve: {
        getAllTheData: questionResolveFunction
    }
}).state('questions.page1', {
    url: 'page1',
    views: {
        'questionView': {
            templateURL: 'template.html',
            controller: 'Page1Ctrl'
        }
    }   
}).state('questions.page2', {
    url: 'page2',
    views: {
        'questionView': {
            templateURL: 'template.html',
            controller: 'Page2Ctrl'
        }
    }
}); 

A user may choose to navigate to page 2. However I do not want them to view page 2 until they have completed page 1. The required information to determine whether or not they can view this page comes from the getAllTheData resolve in the parent state, hence I cannot use a generic $urlRouterProvider.rule() because if someone goes directly to this state from outside the app, it will have no idea about the data when it is first called. This is the outcome I want:

index.html/questions/page2 -> Completed page 1 = true --> go to page 2 index.html/questions/page2 -> Completed page 1 = false -> go to page 1 (don't even attempt to resolve or load page 2)

The example given is a very simplified version of the problem, but should cover everything, let me know if it doesn't. Thanks in advance for the help.

Answers


Need Your Help

MPMoviePlayerController audio/video out of sync

objective-c audio mpmovieplayercontroller sync

In my iPad App, I create an MPMoviePlayerController that plays an MP4 off of a website. In the MP4 there are people talking. In the App, I have noticed that the audio and video are out of sync by...

How can I get the content of a cell in a grid in C#?

c# wpf xaml grid

I need to get the content of cell in a Grid in C#. Is there a way to do something like this?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.