问题在angularjs html5Mode [英] Issue with html5Mode in angularjs

查看:139
本文介绍了问题在angularjs html5Mode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除 index.html的使用 html5Mode(真)在angularjs的url,这是code:

I'm trying to remove index.html of the url using html5Mode(true) in angularjs, this is the code:

angular.module('myApp', [
  'ngRoute',
  'myApp.filters',
  'myApp.services',
  'myApp.directives',
  'myApp.controllers'
]).
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
  $routeProvider.when('/home', {templateUrl: 'views/home.html'});
  $routeProvider.when('/about', {templateUrl: 'views/about.html'});
  $routeProvider.otherwise({redirectTo: '/'});
}]);

如果我不写 $ locationProvider.html5Mode(真); 的URL显示:

If I dont write $locationProvider.html5Mode(true); the url shows:

本地主机(端口)/MyApplication/index.html

localhost:(port)/MyApplication/index.html

如果我写的 $ locationProvider.html5Mode(真); 的URL显示:

If I write $locationProvider.html5Mode(true); the url shows:

本地主机:(口)

所有MyApplication 被删除的url。
我想要的网址显示:

MyApplication is removed of the url. And I want the url shows:

本地主机(港)/所有MyApplication /

localhost:(port)/MyApplication/

我在做什么错?有什么问题?

What I'm doing wrong? What's the problem?

更新:

应该如何显示我的< A> 标签?现在我有:

How should show my <a> tags? Right now I have:

<a href="#/about">About</>

当我点击链接,链接显示:

When I click on the link, the url shows:

本地主机(端口)/MyApplication/index.html#/about

localhost:(port)/MyApplication/index.html#/about

我迷路了这一点。

在此先感谢!

推荐答案

如果您的应用程序在 /所有MyApplication / 运行,尝试设置基本路径在您的index.html和交换机 html5Mode

If your application runs under /MyApplication/ try to set the base path in your index.html and switch on html5Mode:

<html>
  <head>
    <base href="/MyApplication/index.html" />
    ...

请参阅使用$地点

这篇关于问题在angularjs html5Mode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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