Angular JS 没有重定向到新模板 (ngRoute)

Angular JS not redirecting to a new template (ngRoute)

我的路由设置如下:

function routing($routeProvider) {
$routeProvider
    .when('/', {
        templateUrl: 'templates/registration.html'
    }).when('/chatroom', {
        templateUrl: 'templates/ChatRoom.html',
        controller: 'mainController'
    });
}

messagingApp.config([
    '$routeProvider',
    '$locationProvider',
    routing
]);

当我进入 localhost:8080/ 时,它成功加载了 registration.html。我的registration.html如下:

<a href="#/chatroom">Click</a>

当我点击上面的 a 标签时,它仍然只显示 registration.html。点击标签后url变为http://localhost:8080/#!/#%2Fchatroom。我希望它在单击时加载 ChatRoom.html。任何帮助将不胜感激。

将此添加到 html <head> 部分:

<base href="/">

在路线中添加:

$locationProvider.html5Mode(true);

在锚定元素中删除 url 之前的 #

这可能会解决您的问题