angularjs 中的 html5Mode 问题 [英] Issue with html5Mode in angularjs

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

问题描述

我正在尝试使用 angularjs 中的 html5Mode(true) 删除 url 的 index.html,这是代码:

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(true); url 显示:

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

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

localhost:(port)/MyApplication/index.html

如果我写 $locationProvider.html5Mode(true); 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?

更新:

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

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" />
    ...

请参阅使用 $location.

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

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