0

我有一个简单的 AngularJS 应用程序,其中没有与 nodeJS 相关的代码。我在从 url 中删除 # 时遇到问题。我使用 ui-routes 进行路由。

'use strict';
var app = angular.module('myapp', ['ui-router']).
        config(['$stateProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
               $locationProvider.html5Mode(true);
                $stateProvider.
                        state('home', {
                            url: '/',
                            templateUrl: 'views/index.html'
                        })
                        .state('where-am-i', {
                            url: '/where-am-i',
                            templateUrl: 'views/where_am_i.html',
                            controller: 'mainCtrl'
                        })
                        .state('audience', {
                            url: '/audience',
                            templateUrl: 'views/audience.html',
                            controller: 'mainCtrl'
                        });

            }]);

还将基本标记添加到我的 index.html 的头部。

<base href='/' />

也试过不需要基地,但仍然无法让它工作。

$locationProvider.html5Mode({
            enabled: true,
            requireBase: false
        });

添加基本​​标记会显示我在 index.html 文件中包含的所有资产的 404。

需要一个快速简单的解决方案。

先感谢您!

4

1 回答 1

0

$locationProvider.html5Mode(true);在下面添加一行:

$locationProvider.hashPrefix('');

希望它有效。

于 2020-07-12T06:35:49.537 回答