【问题标题】:Angular 1.4.8 Route Params htaccessAngular 1.4.8 路由参数 htaccess
【发布时间】:2018-04-23 02:37:30
【问题描述】:

我在尝试在第二级刷新我的页面时遇到问题,当通过这样的路由角度设置参数时:

localhost/ADMIN/page/1

在哪里

localhost/BASE_FOLDER/ROUTE/ROUT_PARAM

所以,我在我的路由应用程序中定义了这个:

app.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) {
      $routeProvider.
        when('/home', {
          templateUrl: 'template/home.html',
          controller: 'homeController'
        })
        .when('/page', {
          templateUrl: 'template/page-list.html',
          controller: 'pageListController'
        })
        .when('/page/:id', {
          templateUrl: 'template/page-details.html',
          controller: 'pageDetailsController'
        })
        .when('/', {
          redirectTo: 'home'
        })
        .otherwise({
          redirectTo: '404'
        });
        $locationProvider.html5Mode(true);
        $locationProvider.hashPrefix('');
    }]);

所以刷新的问题只有在/page/:id for rewrite rules 的时候才会有错误,我确定,但是我找不到错误,希望你能看到,谢谢。

RewriteEngine on
RewriteBase /ADMIN/

# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^ - [L]

# Redirect urls without a trailing slash
RewriteRule ^(.*)/$ $1 [L,R=301]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]

这是错误,但看不到。页面全部显示

【问题讨论】:

    标签: javascript php angularjs .htaccess


    【解决方案1】:

    在我看来,这可能是问题所在:

    RewriteRule ^ - [L]
    

    ^ 说“匹配任何东西”

    - 表示“不采取任何行动”

    [L] 表示“最后一条规则”,即在此之后停止处理 RewriteRules

    此 [L] 与“任何”匹配项相结合将导致您在下面的最终重写永远不会执行:

    RewriteRule ^ index.html [L]
    

    【讨论】:

    • 所以,我用你给我的那一行替换了这个 -> "RewriteRule ^ - [L]",但它不起作用,现在它不会从一开始就加载任何 css。 :S
    • 我发现了问题,在index.html中设置base='/ADMIN/'标签的位置很重要,你必须在开始时设置它,否则会报错
    【解决方案2】:

    问题是在 index.html 中设置基本标记

    <html>
      <head>
        ....
        <base href="/ADMIN/" >
      </head>
      <body>
        ...
      </body>
    </html>
    

    'base'标签的位置很重要,因为它需要设置在head标签的第一行,像这样:

    <html>
      <head>
        <base href="/ADMIN/" >
        ....        
      </head>
      <body>
        ...
      </body>
    </html>
    

    解决了! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      相关资源
      最近更新 更多