AngularJS:是否可以在一个应用程序中加载两个不同的html和两个不同的路由器(每个.html一个)?

时间:2015-05-13 09:26:39

标签: angularjs single-page-application angularjs-routing

我有两个HTML文件 - > index.htmlstart.html

到目前为止,我正在开发一个应用程序(一个小应用程序),其中index.html用作主页面,app-route用作应用程序的主路由器。现在,我们正在创建一个更大的应用程序,例如.com网站,并将之前的应用程序与此结合(.com)。

我们不想打扰较小的应用程序代码,我们正在开发一个.com网站,该网站是一个不同的html(start.html)和一个不同的路由器(dot-com-route.js)。现在,每当我尝试加载http://localhost/myApp/app/#/start.html时,它都会使用app-route.js加载index.html?

总是这样,有角度的应用程序会查找要执行的index.html文件吗?

这是我的app-route.js:

smartPrintApp.config(['$routeProvider','$locationProvider',
  function($routeProvider, $locationProvider) {
      $routeProvider.
      when('/', {
        templateUrl: 'pages/smart_print_landing/smart-print-landing.html'
      }).
      when('/index.html', {
        templateUrl: 'pages/smart_print_landing/smart-print-landing.html'
      })
  }
]);

1 个答案:

答案 0 :(得分:2)

当您尝试打开http://localhost/myApp/app/#/start.html时,服务器实际尝试提供的网址部分为http://localhost/myApp/app/。在服务器发送浏览器之后,所请求的页面AngularJS将起作用并在has(#)之后读取该部分以确定使用哪个路由。由于您没有在服务器正在读取的部分中包含特定的HTML文件,因此服务器将提供已设置为默认值的HTML文件(我假设从您获得的行为是index.html)。

因此,为了获得您的第二个目标网页,您应该使用http://localhost/myApp/app/start.html/#/(或类似的内容,具体取决于您希望访问的路线)作为网址。