那里';我的angularJS路线有问题吗
我很难弄明白。我把我的路线配置分为不同的文件,我不知道出了什么问题。基本上,当我在我的页面上放置一个链接,指向angular应用程序中的另一个页面时,它就工作了,但当我复制该url,并将其加载到另一个选项卡或浏览器时,它会给我404。为什么会这样?这是我的密码: 这就是我的那里';我的angularJS路线有问题吗,angularjs,Angularjs,我很难弄明白。我把我的路线配置分为不同的文件,我不知道出了什么问题。基本上,当我在我的页面上放置一个链接,指向angular应用程序中的另一个页面时,它就工作了,但当我复制该url,并将其加载到另一个选项卡或浏览器时,它会给我404。为什么会这样?这是我的密码: 这就是我的app config.js的样子: (function () { 'use strict'; angular .module('myApp') .run(appRunner)
app config.js
的样子:
(function () {
'use strict';
angular
.module('myApp')
.run(appRunner)
.config(appConfig);
appRunner.$inject = ['$rootScope', '$route', '$translate']
appConfig.$inject = ['$routeProvider', '$locationProvider', '$translateProvider', 'LANGUAGES', 'TRANSLATIONS'];
function appConfig($routeProvider, $locationProvider, $translateProvider, LANGUAGES, TRANSLATIONS) {
$routeProvider.otherwise({
redirectTo: '/404'
});
$locationProvider.html5Mode(true);
console.log('configured shit...')
configureTranslations() ;
function configureTranslations() {
var english = TRANSLATIONS[LANGUAGES.EN];
var spanish = TRANSLATIONS[LANGUAGES.ES];
$translateProvider.translations(LANGUAGES.EN, english);
$translateProvider.translations(LANGUAGES.ES, spanish);
$translateProvider.preferredLanguage(LANGUAGES.EN);
}
}
function appRunner($rootScope, $route, $translate) {
$rootScope.$on('$routeChangeSuccess', function() {
setPageTitle();
});
function setPageTitle() {
console.log('current route: ', $route.current)
$translate($route.current.title).then(function(pageTitle) {
document.title = pageTitle;
});
}
}
})();
然后,我在另一个页面中有另一个配置路由的文件:
(function () {
'use strict';
angular
.module('myApp.views.caesar')
.config(routeConfig);
routeConfig.$inject = ['$routeProvider'];
function routeConfig($routeProvider) {
$routeProvider.when('/caesar-cipher', {
templateUrl: 'views/caesar-cipher/view.html',
controller: 'CaesarCipherCtrl as caesarCipherCtrl',
title: 'CAESAR.TITLE'
}
});
}
})();
在我的标题中,有一个链接指向/caesar cipher
页面
<a href="/" translate>CAESAR.TITLE</a>
当angular应用程序配置为使用HTML5模式(true)时,您是否对服务器进行了必要的更改?我还没有。我应该对此做更多的研究。
[Fri May 26 2017 02:16:58 GMT+0800 (PHT)] "GET /partials/header/header.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
[Fri May 26 2017 02:16:58 GMT+0800 (PHT)] "GET /views/caesar-cipher/view.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
[Fri May 26 2017 02:16:58 GMT+0800 (PHT)] "GET /images/ciphers_cover.jpg" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
[Fri May 26 2017 02:17:00 GMT+0800 (PHT)] "GET /about" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
[Fri May 26 2017 02:17:00 GMT+0800 (PHT)] "GET /about" Error (404): "Not found"