我正在使用Predix种子,我试图从URL中删除#,这样
http://localhost:5000/#/dash变成了
http://localhost:5000/dash做这件事最好的方法是什么?
seed-app.html页面是我认为可以配置URL结构的地方,它有以下关键元素
...
<!-- 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";
}
}其结果是,我仍然需要使用#作为前缀到达页面。
发布于 2017-02-13 21:46:29
发布于 2019-01-29 13:18:41
新版本的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>https://stackoverflow.com/questions/42201326
复制相似问题