简体   繁体   中英

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.

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.

This is the code I am using:

index.html:

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

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. Thus the app is trying to find "myapp.html" page which is non existing. It should be getting "/" so that it will be redirected to "register-login.html" page where login code is present.

Please let me know where I am going wrong

I solved the issue by using hash URL as shown:

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

I used it in all the files where is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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