URL Variables in AngularJS

For some time I was looking for an answer to this question, so I start to wonder if this is possible.

I am creating a routeProvider configuration in my Angular application that uses both location names and the year parameter to aggregate data. Ideally (although I don’t know if possible), I would like to have the following possible URL structures:

'example.com/:country'
'example.com/:country/:year'
'example.com/:country/:state/'
'example.com/:country/:state/:year'
'example.com/:country/:state/:city'
'example.com/:country/:state/:city/:year'

So that the user can delete such URLs: 'example.com/usa'or 'example.com/usa/2012'(if they do not provide a year, he just captures the data of recent years) Obviously, I ran into problems here because when you visit   'example.com/:country/:state/', the route provider expects the state to be the parameter of the year.

My question is to allow such a structure? I'm not quite sure where to start adding logic to allow both, or, if possible, so any advice is greatly appreciated.

* * Change I read a little about the parameters ui.router and state, although, admittedly, I know little about it, but I ask myself, can this somehow work?

+4
source share
2 answers

REST principles show that your URLs must describe the resource (s) you want to receive.

This seems clear enough, however, in my opinion, at least it still implies two valid approaches.

HTTP request

-, URL-, query, HTTP- , , , ( query string). URL REST , HTTP.

, HTTP . - bad thing, , , , , ( RPC).

The Query
'example.com/country'

The Refinement Parameters
 - year or  
 - city or  
 - state

URL- REST

, REST, , country+city+state+year URL.

, , , , . URL, .

, URL - :

//Syntax for ui.router
'example.com/country/{country}'
'example.com/country/{country}/year/{year}'
'example.com/country/state/{state}'
'example.com/country/state/{state}/year/{year}'
'example.com/country/state/{state}/city/{city}'
'example.com/country/state/{state}/city/{city}/year/{year}'

, , , , .

, , , , , URL- , , URL- , , , .

, ui.router AngularJS, , URL-, . , SPA "", , , . URL-, , API, , .

, API - .

0

? :

example.com/:country?year=2013&state=NY

, , .

0

All Articles