Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 聚合物2新页面获取404_Html_Polymer_Polymer 2.x - Fatal编程技术网

Html 聚合物2新页面获取404

Html 聚合物2新页面获取404,html,polymer,polymer-2.x,Html,Polymer,Polymer 2.x,我按照《聚合物指南》创建了一个新页面:。但当我点击导航菜单项“新视图”时,我得到的是“哎呀,你撞到了404,回老家。”而不是我的新视图。我试着编辑现有的页面,一切似乎都很好,但我的新页面不行。我的文件和教程一模一样,我检查了很多 my-app.html: <!-- @license Copyright (c) 2016 The Polymer Project Authors. All rights reserved. This code may only be used under the

我按照《聚合物指南》创建了一个新页面:。但当我点击导航菜单项“新视图”时,我得到的是“哎呀,你撞到了404,回老家。”而不是我的新视图。我试着编辑现有的页面,一切似乎都很好,但我的新页面不行。我的文件和教程一模一样,我检查了很多

my-app.html:

<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
<link rel="import" href="../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../bower_components/app-layout/app-header-layout/app-header-layout.html">
<link rel="import" href="../bower_components/app-layout/app-scroll-effects/app-scroll-effects.html">
<link rel="import" href="../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../bower_components/app-route/app-location.html">
<link rel="import" href="../bower_components/app-route/app-route.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="my-icons.html">

<link rel="lazy-import" href="my-view1.html">
<link rel="lazy-import" href="my-view2.html">
<link rel="lazy-import" href="my-view3.html">
<link rel="lazy-import" href="my-new-view.html">
<link rel="lazy-import" href="my-view404.html">

<dom-module id="my-app">
  <template>
    <style>
      :host {
        --app-primary-color: #4285f4;
        --app-secondary-color: black;

        display: block;
      }

      app-drawer-layout:not([narrow]) [drawer-toggle] {
        display: none;
      }

      app-header {
        color: #fff;
        background-color: var(--app-primary-color);
      }

      app-header paper-icon-button {
        --paper-icon-button-ink-color: white;
      }

      .drawer-list {
        margin: 0 20px;
      }

      .drawer-list a {
        display: block;
        padding: 0 16px;
        text-decoration: none;
        color: var(--app-secondary-color);
        line-height: 40px;
      }

      .drawer-list a.iron-selected {
        color: black;
        font-weight: bold;
      }
    </style>

    <app-location
        route="{{route}}"
        url-space-regex="^[[rootPath]]">
    </app-location>

    <app-route
        route="{{route}}"
        pattern="[[rootPath]]:page"
        data="{{routeData}}"
        tail="{{subroute}}">
    </app-route>

    <app-drawer-layout fullbleed narrow="{{narrow}}">
      <!-- Drawer content -->
      <app-drawer id="drawer" slot="drawer" swipe-open="[[narrow]]">
        <app-toolbar>Menu</app-toolbar>
        <iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
          <a name="view1" href="/view1">View One</a>
          <a name="view2" href="/view2">View Two</a>
          <a name="view3" href="/view3">View Three</a>
          <a name="new-view" href="/new-view">New View</a>
        </iron-selector>
      </app-drawer>

      <!-- Main content -->
      <app-header-layout has-scrolling-region>

        <app-header slot="header" condenses reveals effects="waterfall">
          <app-toolbar>
            <paper-icon-button icon="my-icons:menu" drawer-toggle></paper-icon-button>
            <div main-title>My App</div>
          </app-toolbar>
        </app-header>

        <iron-pages
            selected="[[page]]"
            attr-for-selected="name"
            fallback-selection="view404"
            role="main">
          <my-view1 name="view1"></my-view1>
          <my-view2 name="view2"></my-view2>
          <my-view3 name="view3"></my-view3>
          <my-new-view name="new-view"></my-new-view>
          <my-view404 name="view404"></my-view404>
        </iron-pages>
      </app-header-layout>
    </app-drawer-layout>
  </template>

  <script>
    class MyApp extends Polymer.Element {
      static get is() { return 'my-app'; }

      static get properties() {
        return {
          page: {
            type: String,
            reflectToAttribute: true,
            observer: '_pageChanged',
          },
          routeData: Object,
          subroute: String,
          // This shouldn't be neccessary, but the Analyzer isn't picking up
          // Polymer.Element#rootPath
          rootPath: String,
        };
      }

      static get observers() {
        return [
          '_routePageChanged(routeData.page)',
        ];
      }

      _routePageChanged(page) {
        // If no page was found in the route data, page will be an empty string.
        // Default to 'view1' in that case.
        this.page = page || 'view1';

        // Close a non-persistent drawer when the page & route are changed.
        if (!this.$.drawer.persistent) {
          this.$.drawer.close();
        }
      }

      _pageChanged(page) {
        // Load page import on demand. Show 404 page if fails
        var resolvedPageUrl = this.resolveUrl('my-' + page + '.html');
        Polymer.importHref(
            resolvedPageUrl,
            null,
            this._showPage404.bind(this),
            true);
      }

      _showPage404() {
        this.page = 'view404';
      }
    }

    window.customElements.define(MyApp.is, MyApp);
  </script>
</dom-module>

:主持人{
--app原色:#4285f4;
--app二次颜色:黑色;
显示:块;
}
应用程序抽屉布局:非([窄])[抽屉切换]{
显示:无;
}
应用程序标题{
颜色:#fff;
背景色:var(--app原色);
}
应用程序标题纸图标按钮{
--纸张图标按钮墨水颜色:白色;
}
1.出票人名单{
利润率:0.20px;
}
.出票人名单a{
显示:块;
填充:0 16px;
文字装饰:无;
颜色:var(--app二次色);
线高:40px;
}
.抽屉列表a.已选定{
颜色:黑色;
字体大小:粗体;
}
我的应用程序
类MyApp扩展了Polymer.Element{
静态get是(){return'my app';}
静态获取属性(){
返回{
第页:{
类型:字符串,
reflectToAttribute:true,
观察者:''u pageChanged',
},
routeData:对象,
子例程:字符串,
//这应该不是必要的,但分析仪没有检测到
//聚合物.元素#根路径
根路径:字符串,
};
}
静态获取观察器(){
返回[
“_routePageChanged(routeData.page)”,
];
}
_routePageChanged(第页){
//如果在路由数据中找不到页面,则页面将是空字符串。
//在这种情况下,默认设置为“view1”。
this.page=page | |“view1”;
//更改页面和路径时关闭非持久性抽屉。
如果(!this.$.drawer.persistent){
此.drawer.close();
}
}
_页面更改(第页){
//按需加载页面导入。如果失败,则显示404页面
var resolvedPageUrl=this.resolveUrl('my-'+page+'.html');
聚合物进口参考号(
resolvedPageUrl,
无效的
这个。_showPage404.bind(这个),
正确的);
}
_showPage404(){
this.page='view404';
}
}
window.customElements.define(MyApp.is,MyApp);
my-new-view.html:

<!-- Load the Polymer.Element base class -->
<link rel="import" href="../bower_components/polymer/polymer-element.html">

<dom-module id="my-new-view">
  <!-- Defines the element's style and local DOM -->
  <template>
    <style>
      :host {
        display: block;

        padding: 16px;
      }
    </style>

    <h1>New viewwww</h1>
  </template>
  <script>
    // Your new element extends the Polymer.Element base class
    class MyNewView extends Polymer.Element {
      static get is() { return 'my-new-view'; }
    }
    //Now, register your new custom element so the browser can use it
    customElements.define(MyNewView.is, MyNewView);
  </script>
</dom-module>

:主持人{
显示:块;
填充:16px;
}
新视野www
//新元素扩展了Polymer.element基类
类MyNewView扩展了Polymer.Element{
静态get是(){return'mynewview';}
}
//现在,注册新的自定义元素,以便浏览器可以使用它
定义(MyNewView.is,MyNewView);

接缝都很好,就像您在《聚合物项目》的页面上指出的那样,但您唯一需要纠正的是。如果要使用
惰性导入导入
导入页面,则需要在
之间移动此行,例如:

... 
<!--import all necessary library ABOVE as you did and PLUS below  -->
<link rel="import" href="../lazy-imports-mixin.html">
...
<dom-module id="my-app">
    <link rel="lazy-import" group="lazy" href="my-view1.html">
    <link rel="lazy-import" group="lazy" href="my-view2.html">
    <link rel="lazy-import" group="lazy" href="my-view3.html">
    <link rel="lazy-import" group="lazy" href="my-new-view.html">
    <link rel="lazy-import" group="lazy" href="my-view404.html">
  <template>
...
请参阅

或者,您可以只在同一位置导入页面,但不使用
延迟导入
,如:

<link rel="import" href="my-view1.html">
<link rel="import" href="my-view2.html">
<link rel="import" href="my-view3.html">
<link rel="import" href="my-new-view.html">
<link rel="import" href="my-view404.html">

实际上是函数
\u pageChanged
进行导入,懒惰导入的东西只是用来欺骗linter

也就是说,我不明白为什么它不能工作,除非它与服务器的问题


如果你浏览到my-new-view.html页面,会不会是404?如果是这样,则不提供页面。同时查看控制台是否抛出错误。

我猜错误出现在函数\uuu页面更改和链接函数中。请参阅:这取决于您的页面名称my-“page”。。。我想你应该将你的页面命名为“我的页码”或重写开始代码

如果你需要更多信息,请评论并询问。不要在你不确定的地方发布答案。
<link rel="import" href="my-view1.html">
<link rel="import" href="my-view2.html">
<link rel="import" href="my-view3.html">
<link rel="import" href="my-new-view.html">
<link rel="import" href="my-view404.html">