我正在使用Predix UI seed,并且尝试从URL中删除#,因此

http://localhost:5000/#/dash


变成

http://localhost:5000/dash


最好的方法是什么?

我认为可以配置URL结构的seed-app.html页具有以下关键元素

...
<!-- app route -->
<link rel="import" href="../../bower_components/app-route/app-location.html">
<link rel="import" href="../../bower_components/app-route/app-route.html">
...
<!-- px components -->
<link rel="import" href="../../bower_components/px-app-nav/px-app-nav.html">
<link rel="import" href="../../bower_components/px-view/px-view.html">

<!-- app-location captures url and assigns _route value -->
          <app-location
            id="carbonLocation"
            route="{{_route}}"
            use-hash-as-path>
          </app-location>

          <!-- /dashboards route and view -->
          <app-route
            route="[[_route]]"
            pattern="/dashboards"
            active="{{_dashboardsActive}}">
          </app-route>
...
 <script>
    Polymer({
      is: 'seed-app',
      properties: {
        routesActive: {
          type: Boolean,
          value: false
        },
...
 // Sets app default base URL for client-side routing
        pathPrefix: {
          type: String,
          value: '#'
        }
      },
      ready: function(){
        this._checkForDefaultRoute();
      },
      _checkForDefaultRoute: function() {
        // set default route to /dashboards
        var l = window.location;
        if((l.hash === "#/" || l.hash === "") && l.pathname === "/") {
          l.hash = "/dashboards";
        }
      }
    });
  </script>


我删除了pathPrefix

pathPrefix: {
   type: String,
   value: ''
}


并像这样更改_checkForDefaultRoute函数

_checkForDefaultRoute: function() {
    // set default route to /runtime
    var l = window.location;
    if((l.hash==="") && l.pathname==="/"){
      l.pathname="/login";
    }
  }


结果是我仍然需要使用#作为前缀来访问页面。

最佳答案

请在Predix论坛中查看此问题的答案:
https://forum.predix.io/questions/18308/predix-ui-seed-app-remove-hash-from-url.html#answer-18365

关于javascript - Predix UI Seed应用-从URL删除哈希,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42201326/

10-10 22:02