在路由子目录Angular.js [英] Routing in subdirectory in Angular.js

查看:194
本文介绍了在路由子目录Angular.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能发展,将在其将要部署的网络目录路径中抽象出来的​​一种方式的Angular.js应用程序?

我试图把一个Angular.js应用在Web服务器子目录 http://example.com/myproject/ ,但是路由器重定向我到Web服务器根目录 - 。 http://example.com

下面是我的Angular.js的应用程序:

VAR的myproject = angular.module('MyProject的',[]);myproject.config(函数($ routeProvider,$ locationProvider){
  $ routeProvider。
    当('/',{templateUrl:'谐音/ index.html的,控制器:IndexCtrl})。
    否则({redirectTo:'/'});  $ locationProvider.html5Mode(真);
});功能IndexCtrl($范围,$位置){}


解决方案

尝试设置<基本href =/ sudirectory/> < HEAD>< /头> 。这就是我需要做什么才能让我的工作,IIRC

谨慎的字:这将弄乱有HREF =#,以及充当根图像索马里红新月会之类的任何锚标签

Is it possible to develop an Angular.js application in a way that would be abstracted from the the web directory path in which it will be deployed?

I am trying to put an Angular.js app in a web server subdirectory http://example.com/myproject/, but the router redirects me to the web server root -- http://example.com.

Below is my Angular.js app:

var myproject = angular.module('myproject', []);

myproject.config(function($routeProvider, $locationProvider) {
  $routeProvider.
    when('/', {templateUrl: 'partials/index.html', controller: IndexCtrl}).
    otherwise({redirectTo: '/'});

  $locationProvider.html5Mode(true);
});



function IndexCtrl($scope, $location) {

}

解决方案

Try setting a <base href="/sudirectory"/> in your <head></head>. That's what I needed to do to get mine working, IIRC

Word of caution: This will mess with any anchor tags that have href="#", as well as act as the root for image srcs and the like.

这篇关于在路由子目录Angular.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆