2

I'm trying to match example.com/?ref=thing in my router.

Going off this example in the docs (https://github.com/angular-ui/ui-router/wiki/URL-Routing):

url: "/contacts?myParam"
// will match to url of "/contacts?myParam=value"

I tried:

url: "/?ref"

But that doesn't work (ie. it does not direct me to that route)

I've also tried: "/ref/:value", but no. Also: /? nope

All I can find in the docs is examples of routes that start with a base files or user.

1 Answers1

1

For example if you have this in your $stateProvider:

.state('listview', {
  url: '/listview?:id', // Output /listview?id=1234
  templateUrl: 'templates/listview.html',
  controller: 'listviewController'
});

Then you can just call the following function in one of your controllers and it will go to listview with a given id:

var url_id = 1234;
$state.go('listview', {id: url_id});

You can also do it like this:

.state('listview', {
  url: '/listview/:id', // Output /listview/1234
  templateUrl: 'templates/listview.html',
  controller: 'listviewController'
});

Also this will work:

.state('listview', {
  url: '/listview/?:id', // Output /listview/?id=1234
  templateUrl: 'templates/listview.html',
  controller: 'listviewController'
});

Hopefully this gives you the right direction.

thepio
  • 6,193
  • 5
  • 35
  • 54
  • Problem is, I have nothing before the `/?`, so no `/listview` – MoteyMcMote May 04 '16 at 14:22
  • Well that's not how angular works I'm sorry. Can't you just add maybe one letter in the state url? For example `/a?:id` – thepio May 04 '16 at 14:55
  • Maybe you can take a look at AngularJS abstract states: https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states – thepio May 04 '16 at 14:57