Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs $routeProvider未重定向_Angularjs - Fatal编程技术网

Angularjs $routeProvider未重定向

Angularjs $routeProvider未重定向,angularjs,Angularjs,我有这样的config() function config($httpProvider, $routeProvider) { $httpProvider.interceptors.push('httpInterceptorService'); $routeProvider .when('/detail/:id', { controller: 'CourseDetailController', controllerAs: 'vm', templateUrl: 'te

我有这样的config()

function config($httpProvider, $routeProvider) {

$httpProvider.interceptors.push('httpInterceptorService');

$routeProvider
  .when('/detail/:id', {
    controller: 'CourseDetailController',
    controllerAs: 'vm',
    templateUrl: 'templates/course-detail.html'
  })
.otherwise({
    redirectTo: '/'
  });
}
看法

我试过了

  • href=“/#/detail/{{course.\u id}}}”
    中删除了
    /#
    ,但这次
    URL
    变为
    http://localhost:5000/detail/57029ed4795118be119cc43d
    ,而不是拿起angular router并发出服务器请求

  • 手动访问地址栏中的
    URL
    http://localhost:5000/#!/详图/F57029ed4795118be119cc43d 没有编码字符,此时间视图已正确更改


  • 有什么想法吗?

    在配置中执行此操作

    function config($httpProvider, $routeProvider, $locationProvider) {
        $locationProvider.hashPrefix('');
    
    然后尝试使用ng href

    <a class="course--module course--link" ng-href="/#/detail/{{ course._id   }}">
    

    您需要在对象窗口中使用浏览器级API,或者可以在控制器中插入$window引用

    • window.location.href=”http://www.google.com";
    • $window.location.href=”http://www.google.com";

    您是否使用angular 1.6?如果我解决了您的问题,请接受答案。
    function config($httpProvider, $routeProvider, $locationProvider) {
        $locationProvider.hashPrefix('');
    
    <a class="course--module course--link" ng-href="/#/detail/{{ course._id   }}">
    
    <a class="course--module course--link" ng-href="/#!/detail/{{ course._id   }}">