Как я могу решить: шаблон HTML должен содержать один корневой элемент - PullRequest
0 голосов
/ 18 октября 2019

Я пытаюсь использовать onsen навигатор с несколькими файлами ".html", но я получаю ту же ошибку, независимо от того, что я пробовал

Мой сценарий

  • -www
  • / scripts
  • index.html
  • home.html

Я хочу перейти от index.html к home.html

Ошибка:

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

Мой 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>

Мой 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>

И мой скрипт:

    function loginNomral(){
        const navigator = document.querySelector('#navigator');
        navigator.resetToPage('home.html');

        ons.notification.alert('test');
    }

Пожалуйста, помогите: v РЕДАКТИРОВАТЬ: Это для мобильного приложения Полный просмотр HTML: Изображение index.html Изображение home.html

Ответы [ 4 ]

0 голосов
/ 19 октября 2019

Решение было простым, через несколько часов я просто удалил весь формат 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>

до этого:

<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>
0 голосов
/ 18 октября 2019

Могу поспорить, что вы создаете какие-то компоненты ... и эти компоненты выглядят так:

<header>...</header>

<section>...</section>

Который ... имеет 2 "корневых" элемента ... верно?

<aside class='component-name'>
  <header>...</header>

  <section>...</section>
</aside>

Это 1.

0 голосов
/ 18 октября 2019

Навигатор пользовательского интерфейса Onsen работает с шаблонами, в которых вы указываете содержание своей страницы, вам не нужно создавать другой html-файл для указания другой страницы

document.addEventListener('init', function(event) {
  var page = event.target;

  if (page.id === 'page1') {
    page.querySelector('#push-button').onclick = function() {
      document.querySelector('#myNavigator').pushPage('page2.html', {data: {title: 'Page 2'}});
    };
  } else if (page.id === 'page2') {
    page.querySelector('ons-toolbar .center').innerHTML = page.data.title;
  }
});
   <!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>App</title>
</head>
<body>
    <ons-navigator swipeable id="myNavigator" page="page1.html"></ons-navigator>

<template id="page1.html">
  <ons-page id="page1">
    <ons-toolbar>
      <div class="center">Page 1</div>
    </ons-toolbar>

    <p>This is the first page.</p>

    <ons-button id="push-button">Push page</ons-button>
  </ons-page>
</template>

<template id="page2.html">
  <ons-page id="page2">
    <ons-toolbar>
      <div class="left"><ons-back-button>Page 1</ons-back-button></div>
      <div class="center"></div>
    </ons-toolbar>

    <p>This is the second page.</p>
  </ons-page>
</template>
</body>
</html>
0 голосов
/ 18 октября 2019

Как видно из вашего кода, у вас есть </head> без открытия <head>

, но основная проблема в том, что вы не можете иметь 2 тега в качестве корня, то есть вам нужно будет обернуть иходиночный <html></html> тег

как этот:

<html>
   <head>
      <title>Page Title</title>
   </head>
   <body>
      <h1>My First Heading</h1>
      <p>My first paragraph.</p>
   </body>
</html>
...