How to setup my url route in my case?

45 Views Asked by At

I am trying to capture a route to be something like

www.mysite.com/#name=ted&location=ca

I am using stateprovider and I setup as follow:

 $stateProvider
   .state('home', {
      url: '/#name',
      controller: function () {
         alert('here')
         do stuff...
      }
 })

but for some reason, alert never trigger.

Can someone help me about it? Thanks a lot!

3

There are 3 best solutions below

0
On

To get params via query string you can use try:

 $stateProvider
   .state('home', {
      url: '/?name&location',
      controller: function () {
         alert('here')
         do stuff...
      }
 })

# will be there if HTML5 mode is disabled.

0
On
    var app= angular.module('appName', []);

    app.config(['$routeProvider',
    function($routeProvider) {
    $routeProvider.
    when('/home', {
    templateUrl: 'templates/home.html',
    controller: 'AddOrderController'
     }).
     when('/contact', {
    templateUrl: 'templates/contact.html',
    controller: 'ShowOrdersController'
     }).
    otherwise({
    redirectTo: '/home'
    });
    }]);

Try This Is Example Of Navigation Using With route Providers .

0
On

When using ui.router, all routes need a template, include that in your state, remove the # sign from the URL and it should work