4

Terminology

  • #foo: slashless scheme
  • #/foo: slashy scheme

Background

There are certain legacy parts of the application which use (and rely on) the slashless scheme. I would like to introduce Angular routing (probably with ui-router) in a non-destructive way, such that doesn't interfere with the legacy routing so that part of the application could be gracefully phased out over time. Once that happens the all-angular app could switch to the slashy scheme all at once.

So far

I tried setting $locationProvider.hashPrefix('') to an empty string, but it seems you can only set the string between # and /, so that didn't work.

Options

It seems I can either

  • rewrite legacy parts of the app, or
  • rewrite Angular's $locationProvider.hashPrefix to include '/' by default. Therefore setting it to '' would become meaningful.

Both of these options seem very time-consuming.

Do you know about a better way to make Angular recognize the slashless scheme?

Francisc
  • 77,430
  • 63
  • 180
  • 276
Wizek
  • 4,854
  • 2
  • 25
  • 52
  • If I get your question correctly, you should use the HTML routing mode. Here is a similar reference: http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashbang-mode-link-rewriting – Tomer Feb 18 '14 at 23:17

1 Answers1

1

You can try using redirects!

With ui-router:

app.config(function ($urlRouterProvider) {
  // when there is an 'old' route, redirect to new one
  $urlRouterProvider.when('foo', '/foo');

  // You can also use regex for the match parameter
  $urlRouterProvider.when(/(\w+)/i, '/$1'); // UNTESTED!!!!!!
})

Reference about ui-router wiki

I'm sorry but hashtags are quite hard to test in plunkers/fiddles, so i'm not providing one for now...

Valerio
  • 2,390
  • 3
  • 24
  • 34
  • Hmm, doesn't this do the opposite of what my question says? I'd like `#foo` **NOT** to redirect to `#/foo`. – Wizek Feb 28 '14 at 09:30