Angularjs Angular Js正在从URL中删除子目录
我已将Angular应用程序安装在如下位置:Angularjs Angular Js正在从URL中删除子目录,angularjs,joomla,angularjs-scope,angular-ui-router,angular-routing,Angularjs,Joomla,Angularjs Scope,Angular Ui Router,Angular Routing,我已将Angular应用程序安装在如下位置: http://example.com/my-app 我的应用程序路由如下所示: var myApp = angular.module('myApp', ['ngRoute','ngAnimate', 'ui.bootstrap', 'angularFileUpload']); myApp.config(['$routeProvider', function($routeProvider) { $routeProvider
http://example.com/my-app
我的应用程序路由如下所示:
var myApp = angular.module('myApp', ['ngRoute','ngAnimate', 'ui.bootstrap', 'angularFileUpload']);
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/templates', {
controller: 'TemplatesController',
templateUrl: '/components/com_myApp/myApp/views/templates/template-list.html'
})
.when('/apps', {
controller: 'AppController',
templateUrl: '/components/com_myApp/myApp/views/apps/app-list.html'
})
.otherwise({
redirectTo: '/templates'
});
}]);
现在发生的是,当我转到http://example.com/my-app
,url而不是显示http://example.com/my-app#/templates
它显示为http://example.com/templates
似乎否则
条件基本上是从url中删除基本目录my app 35;
。我一直对此感到困惑,在阅读之后,我还尝试将基本url添加到head标记,并尝试将myApp.config
更改为:
myApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
....
}
但是,尽管在像上面那样使用$locationProvider
时,路由似乎可以工作,但基本url仍然没有显示我想要的方式。url显示如下http://example.com/templates
在url路径中没有我的应用程序
。我不想从URL中删除基本路径,我希望URL显示如下http://example.com/my-app/..xyz...
Angular为什么要这样做?之所以发生这种情况,是因为您已通过指定
$locationProvider.html5Mode(true)
指示Angular不要使用hashbang URL。删除或注释掉该代码段,如果在根模板文件中指定了
,删除或注释掉这些内容,只需使用ngRoute
而不使用这些内容。你在基本标记中使用了我的意思是两边的反斜杠吗..我的基本url是由Joomla自动创建的,如下所示
#新手我尝试注释$locationProvider.html5Mode(true)
和基本href
,但没有帮助。另外,我上面的第一个示例没有使用locationProvider
,这也有同样的问题。当我访问有角度的页面(如#/templates
)时,路由是有效的,但当我访问默认页面时,路由是有效的http://example.com/my-app
,而不是显示http://example.com/my-app/#templates/
它显示http://example.com/templates
。我上面展示的两个示例都是这种情况(有和没有$locationProvider
)。我的基本url由Joomla自动创建,如下http://example.com/my-app
当我转到http://example.com/my-app
,浏览器中的url显示此内容大约半秒钟http://example.com/my-app#/templates
然后它立即变为http://example.com/templates
。视图正确地显示了模板列表.html
页面,但由于某种原因,url首先显示正确的页面,然后迅速更改为http://example.com/templates
。真奇怪,好吧。问题似乎不在于Angular,而在于Joomla后端如何为处理根url的模板提供服务--/my app
。我对Joomla没有任何经验,但一般来说,后端将索引模板作为静态HTML文件提供,包含
标记中的所有JS脚本(包括Angular),这些JS文件将使Angular能够从后端接管路由(即路由完全由客户端处理)。希望这能为你指明正确的方向。有道理@Rookie。我将从Joomla端更深入地挖掘,看看为什么会出现这种奇怪的行为,我将这个Angular js添加为Joomla组件,并为其创建了一个菜单项。你说的有道理。如果我能够确定问题所在,我会及时更新(希望明天之前)。再次感谢您阅读我的问题,并在查看我的角度设置后写信给我。我很感激:)