0

我正在尝试捕获一条类似于

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

我正在使用stateprovider,我设置如下:

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

但由于某种原因,警报永远不会触发。

有人可以帮我吗?非常感谢!

4

3 回答 3

0

使用 ui.router 时,所有路由都需要一个模板,将其包含在您的状态中,#从 URL 中删除符号,它应该可以工作

于 2016-08-26T04:20:38.290 回答
0

要通过查询字符串获取参数,您可以使用 try:

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

#如果 HTML5 模式被禁用,就会出现。

于 2016-08-26T04:01:29.823 回答
0
    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'
    });
    }]);

试试这是使用路由提供者的导航示例。

于 2016-08-26T04:02:10.943 回答