Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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路由#!问题_Angularjs_Routing - Fatal编程技术网

AngularJS路由#!问题

AngularJS路由#!问题,angularjs,routing,Angularjs,Routing,这个问题以前已经得到了回答,但对于Angular的早期版本可能是这样。我在Angular 1.6.1中工作。HTML5没有添加#!指向URL,但未加载我的分区 HTML: 将所有这些when('./'…更改为when('/'…因为您使用的是HTML5模式true 在angular 1.6版本中,$locationProvider.hashPrefix(“!”);是默认值,请按如下所示进行更改 $locationProvider.html5Mode(true); $locationProvider

这个问题以前已经得到了回答,但对于Angular的早期版本可能是这样。我在Angular 1.6.1中工作。HTML5没有添加#!指向URL,但未加载我的分区

HTML:


将所有这些
when('./'
…更改为
when('/'
…因为您使用的是HTML5模式true

在angular 1.6版本中,
$locationProvider.hashPrefix(“!”);
是默认值,请按如下所示进行更改

$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');
我认为在定义路由时不需要
。我已经删除了三个'when'语句,现在我的'home'和'second'链接将我带到localhost或localhost/second的根目录。路由没有改变,也不显示我的模板内容。你是否输入了html?我有一个元素。当我添加$locationProvider时.html5Mode(true);和$locationProvider.hashPrefix(“”);我得到一个错误:TypeError:dbg在控制台中未定义。
var myApp = angular.module('myApp', ['ngRoute']);

myApp.config(['$routeProvider', '$locationProvider', 
function ($routeProvider, $locationProvider) {

$routeProvider
.when('#/', {
    templateUrl: 'pages/main.html',
    controller: 'mainController'
})

.when('#/second', {
    templateUrl: 'pages/second.html',
    controller: 'secondController'
})

.when('#/second/:num', {
    templateUrl: 'pages/second.html',
    controller: 'secondController'
})

$locationProvider.html5Mode(true);

}]);
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');