导航去除hashbangs不工作后直接url可 [英] Navigating to url directly after removing hashbangs not working

查看:165
本文介绍了导航去除hashbangs不工作后直接url可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的角度为我的应用程序

我想从URL删除#所以我说下面的线为 SO回答

  $ locationProvider.html5Mode({
  启用:真实,
  requireBase:假的
});

在我还增加了以下code作为这里建议中的index.html

 < HEAD>
  <基本href =/>
< /头>

当我浏览到从主页这一切工作正常,但是当我复制网址并在新标签页中打开它,它抛出 404错误

示例

当我启动应用程序,它的开幕的http://本地主机:PORTNO /家居
当我刷新页面,我得到一个404错误。

我应该做哪些配置?

我的code结构如下

  .STATE('tab.home',{
            网址:'/家,
            观点:{
                制表家:{
                    templateUrl:'模板/制表home.html做为',
                    控制器:'templeHome
                }
            }
        })
        .STATE('tab.list',{
            网址:'/名单,
            观点:{
                制表家:{
                    templateUrl:'模板/ list.html',
                    控制器:'templeList
                }
            }
        })


您需要在您的服务器上添加路线,将您重定向到你面前的入口点(即: index.html的

例如,如果你从你家重定向到的http://本地主机:PORTNO /富/条,你需要一个路线来匹配 /富/条一,将您重定向到你的 index.html的

据migth这个样子(注意,这是一个示例$ C $我自己的c代表哈皮写

  server.route([
    {
        方法:GET,
        路径:/富/酒吧',
        处理:函数(请求,回复){
            reply.file('./公共/ index.html的');
        }
    }
    ...

I am using angular for my app

I wanted to remove the # from the url so i added the below lines as suggested in SO answer

$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});

In the index.html I also added the below code as suggested here

<head>
  <base href="/">
</head>

It all works fine when I navigate to pages from the home, but when i copy the url and open it in new tab, it throws 404 error

Example

When I launch the app, it's opening http://localhost:portno/home. When I refresh the page, I'm getting a 404 error.

What other configuration should i make?

My code structure is as below

  .state('tab.home', {
            url: '/home',
            views: {
                'tab-home': {
                    templateUrl: 'templates/tab-home.html',
                    controller: 'templeHome'
                }
            }
        })
        .state('tab.list', {
            url: '/list',
            views: {
                'tab-home': {
                    templateUrl: 'templates/list.html',
                    controller: 'templeList'
                }
            }
        })

解决方案

You need to add a route on your server that will redirect you to the entrypoint of your front (i.e: index.html).

For example, if you were redirected from your home to http://localhost:portno/foo/bar, you'll need a route to match the /foo/bar one that will redirect you to your index.html.

It migth look like this (note that this is an example code of my own written for Hapi):

server.route([
    {
        method: 'GET',
        path: '/foo/bar',
        handler: function(request, reply) {
            reply.file('./public/index.html');
        }
    }
    ...

这篇关于导航去除hashbangs不工作后直接url可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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