【问题标题】:routeProvider only half workingrouteProvider 只工作了一半
【发布时间】:2015-06-07 19:27:00
【问题描述】:

我的app.js 中有以下代码。

var app = angular.module("TacoTime", ['ngRoute']);

app.config(['$routeProvider',
function($routeProvider) { 
$routeProvider
    // route for the home page
    .when('/', {
        templateUrl : 'views/home.html',
        controller  : 'HomeController'
    })

    // route for the directions page
    .when('/list', {
        templateUrl : 'views/list.html',
        controller  : 'ListController'
    })
    .otherwise({ 
      redirectTo: '/' 
    }); 
}]);

当我有普通的/ 时,我会去home.html。当我尝试/lists 时,我收到一条错误消息,提示Nothing 与给定的URI 匹配。

我一直在想我做错了什么。

【问题讨论】:

  • 你使用的是html5mode吗?如果没有,请确保您使用的是 url '#/' 和 '#/list'
  • 在我最初的评论中添加更多内容,您的路线是/list,您说当您尝试/lists 时出现错误...
  • 罗尼 - /list。打错字了,抱歉。我不认为我正在使用 html5mode
  • Nicholas - 当我在浏览器中输入 /#/list 时,它起作用了!谢谢!

标签: angularjs url-routing ngroute


【解决方案1】:

在 templateUrl 中尝试 '/views/list.html'

【讨论】:

    猜你喜欢
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2016-01-29
    相关资源
    最近更新 更多