Sono nuovo di Polymer. Mi metto a scrivere un semplice webapp in cui 1. L'utente prima terra in una pagina di login 2. Se l'utente passa di accesso, allora l'utente direttamente al contenuto della paginaPolymer 1.0 - routing
scrivo un elemento "Login"
<dom-module id="login">
<template>
<!-- local DOM for your element -->
<p>Username</p>
<input class="paper-font-body2" value="{{email::change}}" type="email">
<br/>
<p>Password</p>
<input class="paper-font-body2" value="{{password::change}}" type="password">
<p>{{errorMessage}}</p>
<iron-ajax
id="ajax"
url=""
method="POST"
on-response="signInResponse"
debounce-duration="300">
</iron-ajax>
<button on-click="signIn">Signin</button>
</template>
</dom-module>
<script>
// element registration
Polymer({
is: "login",
// add properties and methods on the element's prototype
properties: {
// declare properties for the element's public API
email: {
type: String,
value: "username"
},
password: {
type: String,
value: "password"
},
errorMessage: {
type: String,
value: ""
}
},
signIn: function() {
this.$.ajax.url = "http://myserver/login/email";
this.$.ajax.params = {"email":this.email, "password": this.password};
this.$.ajax.generateRequest();
},
signInResponse: function(request) {
response = request.detail.response;
console.log(response);
if (response.code == '0') {
this.fire("signin-success", response);
} else {
this.fire("signin-fail", response);
}
}
});
</script>
su index.html (pagina principale), io uso
<self-login
sign-in-success="onSignedIn"
></self-login>
domanda: nel callback onSignedIn(), avrei percorso la mia pagina/contenuto. Come posso fare?
EDIT 1: Come @zacharytamas suggeriscono, cerco di usare app-router come segue
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>app-router</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="stylesheet" href="styles/main.css" shim-shadowdom>
<link rel="import" href="../bower_components/app-router/app-router.html">
</head>
<body unresolved>
<app-router>
<app-route path="/" import="/elements/home-page.html"></app-route>
<app-route path="/test" import="/elements/home-page.html"></app-route>
<app-route path="*" import="/elements/not-found-page.html"></app-route>
</app-router>
<script src="scripts/app.js"></script>
</body>
</html>
casa-page.html
<dom-module id="home-page" noscript>
<template>
<h2>Hello</h2>
</template>
</dom-module>
mostra un pagina vuota quando sfoglio sia su http://localhost:3000/ e http://localhost:3000/test su Chrome. Qualche idea?
Sembra che l'app-rooter non supporti ancora Polymer 1.0 –
Hmm. L'ho usato con Polymer 0.9 la scorsa settimana e l'API tra 0.9 e 1.0 è molto simile. Hai un errore o semplicemente non funziona? – zacharytamas
Sì, ho riscontrato problemi con l'app-router. Vedi il mio EDIT sulla domanda –