1

我正在使用Predix UI 种子,并尝试从 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";
    }
  }

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

4

2 回答 2

2

请在 Predix 论坛中查看此问题的答案:

https://forum.predix.io/questions/18308/predix-ui-seed-app-remove-hash-from-url.html#answer-18365

于 2017-02-13T21:46:29.903 回答
1

predix 示例应用程序的新版本不使用 hash #。请访问

https://github.com/predixdesignsystem/px-sample-app

一般来说,新的 px 应用版本使用 dom-if 来

 <template is="dom-if" if="{{isEqual(selected,'dashboard')}}" restamp>
   <px-sample-dashboard></px-sample-dashboard>
</template>

在哪里

  selected: {
        type: Array,
        value: function() {
          return ["dashboard"];
        }
      },

然后您可以使用px-app-nav选择页面

  <px-app-nav slot="app-nav" selected-route="{{selected}}"
    items='[{"label": "Dashboard","path": "dashboard","icon": "px-fea:dashboard", "id": "dashboard"}]'>
  </px-app-nav>
于 2019-01-29T13:18:41.567 回答