javascript - Angular url 中的 $locationProvider

标签 javascript angularjs html css angular-ui-router

最近开发了一个网站http://www.skduhariya.com ,这完全基于angularJS。我正在使用 ui-router 的概念在静态页面之间进行路由。符号 (#) 显示在 URL 中,如 skduhariya.com/#/blogs

我尝试使用 $locationProvider 从 URL 中删除符号 (#),这样 URL 就变成了 skduhariya.com/blogs

它工作正常,但是,当我们刷新浏览器时,它没有按预期工作。它显示 404-Page Not found。

代码:

function routeConfig($stateProvider, $locationProvider) {      
    $stateProvider.state('public', {
        abstract: true,
        templateUrl: 'src/public/public.html'
    });
    $locationProvider.html5Mode(true);
}

谁能帮我解决这个问题。

最佳答案

您可以观看 here

正如他已经描述的那样:

Server side
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html)

:)

关于javascript - Angular url 中的 $locationProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42432703/

相关文章:

javascript - 有没有一种方法可以在两个 AngularJS Web 解决方案与 Visual Studio 之间共享 javascript 代码?

javascript - 围绕按钮链接到链接的按钮

javascript - 为什么在触发 window.location.reload 时清除其余功能代码?

javascript - 如何从 datalist 返回结果而不出现 "undefined"错误

javascript - 如何从 ajax 调用中过滤 null 或未定义的值?

javascript - 解决从 1.0.5 升级到 angularjs 1.3 时的问题

javascript - 如何在pdfmake文本的开头部分添加制表符空间

javascript - AngularJS orderBy 使用字典顺序,即使是数字

javascript - 使用 jquery append 到类属性

javascript - 无法使用 leanModal 弹出两个不同的弹出窗口