我正在使用Predix UI seed,并且我试图从网址中删除#,以便
http://localhost:5000/#/dash
成为
http://localhost:5000/dash
最好的方法是什么?
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";
}
}
结果是我仍然需要使用#作为前缀来访问页面。
答案 0 :(得分:2)
请参阅Predix论坛中对此问题的回答:
https://forum.predix.io/questions/18308/predix-ui-seed-app-remove-hash-from-url.html#answer-18365
答案 1 :(得分:1)
predix示例应用程序的新版本不使用哈希#
。请访问
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>