0

I'm writing an angular 1.5 app that is relying on a REST service. In some flows the service is asking the client for a redirect URL, attaches params to it and sends the URL to the user.

For most clients the service is using query params, hence when given:

www.myapp.com/myState

it returns

www.myapp.com/myState?myParam=value

But for the angular app, when given:

www.myapp.com/#/myState

it returns

www.myapp.com/?myParam=value#/myState

and that violates the app's routing.

It happens since according to RFC https://www.rfc-editor.org/rfc/rfc3986#section-4.1 everything that follows the # sign is considered the URL fragment and should be at the end of the URL.

I deduct that angular's query params are not exactly RFC legal, and are in fact some kind of "fragment params".

So what is the correct, generic way to build URL's that will be used by various client types: mobile, web, SPA etc. and still be RFC valid?

Community
  • 1
  • 1
Nir Smadar
  • 357
  • 2
  • 5
  • 15
  • so are you suggesting that `myParam` is evaluated server side, and that `myState` is evaluated client side? that's the only way that the example you posted would make sense. – Claies Jul 03 '16 at 15:45
  • @Claies that's exactly it. Since angular can't read anything that precedes the #, it in fact uses the fragment identifier to pass params – Nir Smadar Jul 03 '16 at 22:45
  • "can't read" isn't exactly right; The server ignoring the data following the `#` is more accurate. This isn't specifically an issue that angular can solve. It seems to me that you have *multiple* angular apps, that are each delivered on a specific page based on a server response, and each of these "mini-spas" are handing some internal routing. If you can't consolidate the app into a single spa without server parameters, your only option will probably be some sort of server rewrite utility. – Claies Jul 03 '16 at 22:54
  • also, this isn't specifically an issue isolated to angular; it is actually a side effect of how single page applications use browser tricks in order to avoid server calls. This sort of thing is visible in most all SPA browser frameworks. – Claies Jul 03 '16 at 22:56

1 Answers1

0

Firstly set the $locationProvider.html5Mode(true) in app.js and on index.html write <base href="/"> in Head block.

find more clear answer here : Removing the fragment identifier from AngularJS urls (# symbol)

Community
  • 1
  • 1
Prianca
  • 484
  • 2
  • 8
  • tnx @Prianca I'm aware of that, but I'm asking in more general terms- have in mind that angular still uses the hashbang as a fallback for old browsers, so that won't solve the problem – Nir Smadar Jul 03 '16 at 22:48