0

I have two kinds of states in my $stateProvider which are authenticated user access url and public access url..

I have some sort of urls in public access , the thing is i need to prevent these url to access of authenticated user and need to change the url with another one.

Example Suppose, http://localhost:3000/#/pjobadd/1 is public access url, if authenticated user will access this url i need to change as http://localhost:3000/#/jobadd/1 .

I'm trying to take the solution as bellow

i have attached parameter in state provider like

.state('admin-panel.public.jobadd', {
    url: '/pjobadd/:jobID',
    templateUrl: 'app/public/jobadd.tmpl.html',
    controller: 'PublicJobaddController', 
    resolve: {
           jobAdd: ['Public', '$stateParams', function(Public,$stateParams) {                   
                        return Public.jobAdd($stateParams.jobID);
                    }]
     },
    data: {
        requireChange: 'pjobadd'
    } 
})

and used that requireChange in app.js as following

$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
  if (!Auth.isAuthenticated()){
            var requireChange = toState.data.requireChange;
            console.log(requireChange);
            switch(requireChange){
               case 'pjobadd':
                $state.go('admin-panel.default.jobadd');
               case 'psearch':
                $state.go('admin-panel.default.search');

  }

There are issues i need to append the url passed parameters and $state.go() also not redirecting to the mentioned url. i don't think that it'l be the efficient way.

Can anyone suggest a way to it???

user3391137
  • 431
  • 8
  • 26

1 Answers1

0

check this url ... How to pass parameters using ui-sref in ui-router to controller

can you provide your code here?and give me some more clear information about your requirement..

Community
  • 1
  • 1
roshini
  • 112
  • 7
  • I don't have the problem to pass the parameter to controller. I want to prevent to access the public URLs for logged user. If the logged user tries to access via URL then app needs to redirect to relevant URL for authenticated user. – user3391137 Dec 11 '15 at 12:52
  • It means assume public user can see the jobs by using http://local host/pjobadd/1 we have separate and with more functionalities URL to authenticated user to see the jobs that is http://example/joadd/1 . so when the logged user tries to access the public URL jobad we need to redirect to authenticated URL. – user3391137 Dec 11 '15 at 12:59
  • Which code you need I have posted the codes which are I have changed – user3391137 Dec 11 '15 at 13:06
  • total application or can you create plunker? – roshini Dec 11 '15 at 13:07