1

Making a verify account page and want to be able to pass an email and auth code via url like so:

https://mywebsite.com/[email protected]&code=1234

It looks like I can't do it this way in angular. And should instead be done like this:

https://mywebsite.com/verify/:email/:code

And use $stateParams to grab the vars.

Can you have two different URLs trigger the same state? So both URLs below trigger the same state and the controller checks for the vars and does it's magic.

https://mywebsite.com/verify
https://mywebsite.com/verify/:email/:code
2
  • just mention the same controller and check for $stateParams Commented Nov 26, 2014 at 7:43
  • And just make two different states for it? I don't know why, but that seems sloppy to me. Commented Nov 26, 2014 at 7:44

2 Answers 2

2

You can set the configuration as like below and you can pass the param which is required to send for the url

 $stateProvider.state('verify', {
          url: '/verify?email&code',
          templateUrl: 'verify.html',
          controller: 'verifyCtrl'
        });

working fiddle: http://plnkr.co/edit/AwHkFj?p=preview

Sign up to request clarification or add additional context in comments.

2 Comments

Quick follow up question... is there a way to pass the vars with something like $state.go(...)?
Thanks :) You are welcome..yes check $state.transition
1

Rather than defining the params email and code as path parameters, you could use search parameters and access them via $routeParams.

e.g, your route would be:

$routeProvider.when('/verify', routeConfig);

the URL would be:

https://mywebsite.com/[email protected]&code=1234

And in the controller, you would inject $routeParams and access via:

$routeParams[email]; // = [email protected]
$routeParams[code]; // = 1234

For more info on $routeParams, see https://docs.angularjs.org/api/ngRoute/service/$routeParams

2 Comments

Unfortunately I am using states not routes.
ah, sorry, I missed that you were using ui-router not ng-route :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.