Search code examples
angularjsangularjs-routingplunker

How to specify URL params in Plunker for Angular JS routing?


Now I have Angular JS example with rouring:

How I can specify URL params in Plunker that to check that? I mean to so something like: /test/4 Working example:

[http://plnkr.co/edit/ChMaiougIW4KiNNkUTlO?p=preview][1]

Solution

  • Two changes are required:

    In app.js, you need to configure $locationProvider for html5Mode:

    app.config(['$locationProvider',
      function($locationProvider) {
        $locationProvider
          .html5Mode(true)
          .hashPrefix('!');
      }
    ])
    

    In index.html, you need to make your links relative, using html5Mode like: <a href="test/oleg">Go to test</a>.

    Angular will rewrite the href if the browser doesn't support pushState.