I'm trying to use onsen navigator with multiple ".html" files, but I get the same error, no matters what I've tried
My scenario
I want to go from index.html, to home.html
The error:
Uncaught (in promise) Error: [Onsen UI] HTML template must contain a single root element
at Object.Q.throw (onsenui.min.js:2)
at Object.Q.createElement (onsenui.min.js:2)
at onsenui.min.js:2
My index.html:
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css">
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
<script src='scripts/loginScript.js' type='text/javascript'></script>
<link rel="stylesheet" href="style.css">
<title>Tu Psicologa de Cabecera</title>
</head>
<body>
<ons-navigator id="navigator" page="index.html"></ons-navigator>
<ons-template id="index.html">
<ons-page id="index">
<img class="imagenLogo" src="https://i.imgur.com/cq7BbWn.png">
<ons-card class="loginCard">
<ons-input id="userLogin" modifier="underbar" placeholder="Usuario" style="width: 100%; margin-top: 8px; margin-bottom: 8px;" float></ons-input>
<ons-input id="passLogin" modifier="underbar" placeholder="Contraseña" type="password" style="width: 100%; margin-top: 8px; margin-bottom: 8px;" float></ons-input>
<ons-button class="loginButton" onclick="loginNomral()">ENTRAR</ons-button>
<ons-button class="loginFacebookButton">ENTRAR CON FACEBOOK</ons-button>
<label class="labelRegister">REGISTRARME</ilabel>
</ons-card>
</ons-page>
</ons-template>
<script type="text/javascript" src="cordova.js"></script>
</body>
My home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css">
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
<link rel="stylesheet" href="style.css">
<title></title>
</head>
<body>
<ons-page id="home">
<ons-toolbar>
<div class="left"><ons-back-button>Page 1</ons-back-button></div>
</ons-toolbar>
<p>This is the second page.</p>
</ons-page>
</body>
</html>
And my script:
function loginNomral(){
const navigator = document.querySelector('#navigator');
navigator.resetToPage('home.html');
ons.notification.alert('test');
}
Please help :v EDIT: This is for a mobile app Full html view: Image index.html Image home.html
The solution was simple, after some hours, just I removed all the html format and I keep the tag.
From this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css">
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
<link rel="stylesheet" href="style.css">
<title></title>
</head>
<body>
<ons-page id="home">
<ons-toolbar>
<div class="left"><ons-back-button>Page 1</ons-back-button></div>
</ons-toolbar>
<p>This is the second page.</p>
</ons-page>
</body>
</html>
to this:
<ons-page id="home">
<ons-card class="loginCard">
<ons-input id="userLogin" modifier="underbar" placeholder="Usuario" style="width: 100%; margin-top: 8px; margin-bottom: 8px;" float></ons-input>
<ons-input id="passLogin" modifier="underbar" placeholder="Contraseña" type="password" style="width: 100%; margin-top: 8px; margin-bottom: 8px;" float></ons-input>
<ons-button class="loginButton" onclick="logintest()">ENTRAR</ons-button>
<ons-button class="loginFacebookButton">ENTRAR CON FACEBOOK</ons-button>
<label class="labelRegister">REGISTRARME</ilabel>
</ons-card>
</ons-page>