Routing 如何在聚合物起动器套件中设置baseUrl?

Routing 如何在聚合物起动器套件中设置baseUrl?,routing,polymer,Routing,Polymer,如何在聚合物起动器套件(轻型版)中设置baseUrl (类似:) 我想在子文件夹中运行它 (这里是dl和解压缩的PSK,服务器是xampp): 当我转到该URL时,应用程序将重定向到: 谨此说明: 找不到:。重定向 你可以打开主页吗 没有控制台错误,除了URL问题,应用程序工作正常 下面是app.js: // Sets app default base URL app.baseUrl = '/'; if (window.location.port === '') { // if

如何在聚合物起动器套件(轻型版)中设置baseUrl

(类似:)

我想在子文件夹中运行它 (这里是dl和解压缩的PSK,服务器是xampp):

当我转到该URL时,应用程序将重定向到:

谨此说明:

找不到:。重定向 你可以打开主页吗

没有控制台错误,除了URL问题,应用程序工作正常

下面是
app.js

// Sets app default base URL
  app.baseUrl = '/';

  if (window.location.port === '') {  // if production
    // Uncomment app.baseURL below and
    // set app.baseURL to '/your-pathname/' if running from folder in production
    // app.baseUrl = '/polymer-starter-kit/';


   // If this is baseURL:
   //app.baseUrl = 'http://localhost/test/psk/app/';
   //Then click on the menu -  reloads the page with 404 URL:
   //http://localhost/test/psk/app/users
  }
  ...
// Sets app default base URL
app.baseUrl = '/';
if (window.location.port === '') { // if production
    // Uncomment app.baseURL below and
    // set app.baseURL to '/your-pathname/' if running from folder in production
    app.baseUrl = '/base-url/you/want/to/use/';  // <- Set this here
}
routing.html

<script src="../bower_components/page/page.js"></script>
<script>
  window.addEventListener('WebComponentsReady', function() {

      console.log('routing.html');

    // We use Page.js for routing. This is a Micro
    // client-side router inspired by the Express router
    // More info: https://visionmedia.github.io/page.js/

    // Removes end / from app.baseUrl which page.base requires for production
    if (window.location.port === '') {  // if production
      page.base(app.baseUrl.replace(/\/$/, ''));
       console.log("app.baseUrl");
       console.log(app.baseUrl);
    }

    // Middleware
    function scrollToTop(ctx, next) {
      app.scrollPageToTop();
      next();
    }

    function closeDrawer(ctx, next) {
      app.closeDrawer();
      next();
    }

    function setFocus(selected){
      document.querySelector('section[data-route="' + selected + '"] .page-title').focus();
    }

    // Routes
    page('*', scrollToTop, closeDrawer, function(ctx, next) {
      next();
    });

    page('/', function() {
      app.route = 'home';
      setFocus(app.route);
    });

    page(app.baseUrl, function() {
      app.route = 'home';
      setFocus(app.route);
    });

    page('/users', function() {
      app.route = 'users';
      setFocus(app.route);
    });

    page('/users/:name', function(data) {
      app.route = 'user-info';
      app.params = data.params;
      setFocus(app.route);
    });

    page('/contact', function() {
      app.route = 'contact';
      setFocus(app.route);
    });

    // 404
    page('*', function() {
      app.$.toast.text = 'Can\'t find: ' + window.location.href  + '. Redirected you to Home Page';
      app.$.toast.show();
      page.redirect(app.baseUrl);
    });

    // add #! before urls
    page({
      hashbang: true
    });

  });
</script>

addEventListener('WebComponentsReady',function(){
log('routing.html');
//我们使用Page.js进行路由。这是一个微型
//受Express router启发的客户端路由器
//更多信息:https://visionmedia.github.io/page.js/
//从page.base生产所需的app.baseUrl中删除end/from
if(window.location.port==''){//if生产
page.base(app.baseUrl.replace(/\/$/,“”));
console.log(“app.baseUrl”);
console.log(app.baseUrl);
}
//中间件
函数scrollToTop(ctx,下一个){
app.scrollPageToTop();
next();
}
功能关闭抽屉(ctx,下一个){
app.closeDrawer();
next();
}
功能设置焦点(已选择){
document.querySelector('section[data route=“”+selected+”].page title').focus();
}
//路线
页面(“*”,滚动顶部,closeDrawer,函数(ctx,下一页){
next();
});
页面(“/”,函数(){
app.route=‘home’;
设置焦点(应用程序路径);
});
页面(app.baseUrl,函数(){
app.route=‘home’;
设置焦点(应用程序路径);
});
页面('/users',函数(){
app.route='用户';
设置焦点(应用程序路径);
});
页面('/users/:name',函数(数据){
app.route='用户信息';
app.params=data.params;
设置焦点(应用程序路径);
});
页面('/contact',函数(){
app.route='联系';
设置焦点(应用程序路径);
});
// 404
页面('*',函数(){
app.$.toast.text='找不到:'+window.location.href+'。已将您重定向到主页';
app.$.toast.show();
页面重定向(app.baseUrl);
});
//在URL之前添加#
页面({
哈什邦:是的
});
});

在这里,我绝不会假装给出明确的答案

我认为从子文件夹运行当前不起作用。我尝试过几种黑客(设置app.baseUrl、黑客路线、使用page.base()的各种组合)都没有结果,我暂时放弃了

聚合物现场索赔(撰写本报告时):

应用程序路径0.9.1

app route是一个元素,用于为web应用启用声明式、自描述路由

n、 b.应用程序路线仍处于测试阶段。我们预计它将需要一些改变。我们指望你的反馈

因此,到目前为止我所经历的(并希望与大家分享)是:要么直接从文件、从web服务器的根目录运行应用程序,要么从非标准http端口的根目录运行应用程序(要调试应用程序,您可以使用python http模块或其他一些用于静态文件的小型服务器,这些静态文件将以时尚的方式运行)部署将需要相同的约束

建议的运行方法:

我没有尝试的是使用
.htaccess
重写URL库(这在理论上是可行的,但速度非常慢,因为此类应用程序的应用程序路由计算/反应不会发生在服务器端,而是发生在客户端,并且只适用于类似apache的服务器,而且最不需要的是,您将失去客户端上下文)


老实说,在这个问题上,我宁愿被证明是错的

在不使用端口号(即在生产中)时设置app.baseUrl

app.js
中:

// Sets app default base URL
  app.baseUrl = '/';

  if (window.location.port === '') {  // if production
    // Uncomment app.baseURL below and
    // set app.baseURL to '/your-pathname/' if running from folder in production
    // app.baseUrl = '/polymer-starter-kit/';


   // If this is baseURL:
   //app.baseUrl = 'http://localhost/test/psk/app/';
   //Then click on the menu -  reloads the page with 404 URL:
   //http://localhost/test/psk/app/users
  }
  ...
// Sets app default base URL
app.baseUrl = '/';
if (window.location.port === '') { // if production
    // Uncomment app.baseURL below and
    // set app.baseURL to '/your-pathname/' if running from folder in production
    app.baseUrl = '/base-url/you/want/to/use/';  // <- Set this here
}
//设置应用程序默认的基本URL
app.baseUrl='/';
if(window.location.port==''){//if生产
//取消下面的app.baseURL注释并
//如果从生产环境中的文件夹运行,请将app.baseURL设置为“/your pathname/”

app.baseUrl='/base url/you/want/to/use/';//在试图部署到'/appname'的IIS时遇到了这个问题。通过取消注释
//app.baseUrl='/polymer starter kit/';
app.baseUrl='/IIS/中的应用程序名称;
类似问题,详细回答:类似问题:Did set:app.baseUrl='';Ge在对话框中删除此注释:“找不到:。已将您重定向到主页确定”,菜单也不起作用。