简体   繁体   English

聚合物1.6-应用在刷新后显示空白页。 我在用 <app-route> 路由器

[英]Polymer 1.6 - App shows blank page after refresh. I am using <app-route> router

I am new to Polymer and am using Polymer version 1.6.0. 我是Polymer的新手,正在使用Polymer版本1.6.0。

Use Case : User should see login screen when app is initiated. 用例:启动应用程序时,用户应看到登录屏幕。 After successful login, he should be directed to a content page. 成功登录后,应将他定向到内容页面。

**This is working on my localhost (127.0.0.1/index.html), but when I try to run it on external server with path "myapplication.io/myapp/admin/index.html" it is showing blank screen. **这在我的本地主机(127.0.0.1/index.html)上有效,但是当我尝试在外部服务器上使用路径“ myapplication.io/myapp/admin/index.html”运行它时,它显示空白屏幕。

This is the code I am using: 这是我正在使用的代码:

index.html: index.html的:

<body>
 <myadmin-app></myadmin-app>
</body>

myadmin-app.html: myadmin-app.html:

<app-location route="{{route}}"></app-location>
<app-route
        route="{{route}}"
        pattern="/:page"
        data="{{routeData}}"
        tail="{{subroute}}"
        active="{{active}}"></app-route>

<app-header condenses reveals effects="waterfall">
    <app-toolbar>
        <paper-icon-button icon="menu" drawer-toggle></paper-icon-button>
            <div main-title style="text-align: center;">MY ADMIN</div>
    </app-toolbar>
</app-header>

<iron-pages
                selected="[[page]]"
                attr-for-selected="name"
                selected-attribute="active"
                fallback-selection="not-found"
                role="main">
                <config-option name="config-option"></config-option>
                <register-login name="register-login"></register-login>
                <other-option name="other-option"></other-option>
                <not-found name="not-found"></not-found>
</iron-pages>

<script>
    (function() {
        Polymer({
            is: 'myadmin-app',

            properties: {
                page: {
                    type: String,
                    reflectToAttribute: true,
                    observer: '_pageChanged'
                },
                storedUser: Object
            },

            ready: function(){
            },

            observers: [
                '_routePageChanged(routeData.page)'
            ],

            _routePageChanged: function(page) {
                console.log("routechanged page = " + page);
                this.page = page || 'register-login';
            },

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

            _showPage404: function() {
                this.page = 'not-found';
            }
        });
    }());
</script>

The resolvedPageURL in the above code is coming as "myapp" instead of "/" when I run it on the server. 当我在服务器上运行它时,以上代码中的resolvePageURL以“ myapp”而不是“ /”出现。 Thus the app is trying to find "myapp.html" page which is non existing. 因此,该应用正在尝试查找不存在的“ myapp.html”页面。 It should be getting "/" so that it will be redirected to "register-login.html" page where login code is present. 它应该获取“ /”,以便将其重定向到存在登录代码的“ register-login.html”页面。

Please let me know where I am going wrong 请让我知道我要去哪里了

I solved the issue by using hash URL as shown: 我通过使用如下所示的哈希URL解决了该问题:

<app-location route="{{route}}" use-hash-as-path></app-location>

I used it in all the files where is used. 我在所有使用过的文件中使用了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM