Routeless, targetless, runnable routes

栏目: IT技术 · 发布时间: 6年前

内容简介:Now in beta HCX (HTML Compiler eXtensions) supports routeless, targetless, runnable routes. “What does that mean?”, you might ask. An example shows best:Click on “Show Panel One” and “This is panel one” will show up between the router start and end tags. C

Now in beta HCX (HTML Compiler eXtensions) supports routeless, targetless, runnable routes. “What does that mean?”, you might ask. An example shows best:

<script type="module" src="../hcx-router.js"></script><template id=”panelOne">
  <div>This is panel one.</div>
</template><template id="panelTwo">
  <div>This is panel two.</div>
  <script>alert("You have entered panel two.")</script>
</template><a href="#panelOne">Show Panel One</a>  
<a href="#panelTwo">Show Panel Two</a><hcx-router runnable="true"></hcx-router>

Click on “Show Panel One” and “This is panel one” will show up between the router start and end tags. Clicking on “Show Panel Two” will not only replace the content it will run the script with the alert.

For the above and additional examples in this article see the code in action .

Routing can’t get much simpler than this. Just put an <hcx-router> on your page and any time the # changes, a document element with a matching id will be sought and its contents used to replace the empty space between the start and end tags of the router. And, if you tell the router to make the content runnable, any scripts will also be executed or loaded.

Of course, you can provide a target if you wish by making changes to add a targeted location and configure the router to use it:

<div>
  <div>Dashboard</div>
  <div id="dashboard"></div>
</div><hcx-router target=”#dashboard” runnable=”true”></hcx-router>

And, naturally you can also specify paths to select which router to use:

<a href="#dash1/panelOne">Show Panel One</a>  
<a href="#dash2/panelTwo">Show Panel Two</a>
<div>
  <div>Dashboard One</div>
  <div id="dashOne"></div>
</div><div>
  <div>Dashboard Two</div>
  <div id="dashTwo"></div>
</div><hcx-router path="dash1/:$to" target="#dashOne" runnable="true">
</hcx-router><hcx-router path="dash2/:$to" target="#dashTwo" runnable="true"></hcx-router>

In this case we used a special parameterized path containing :$to to specify the source of the content. The more conventional method used by Vue is also possible if a RegExp is used for the path:

<a href="#dash1/panelOne">Show Panel One</a>  
<a href="#dash2/panelTwo">Show Panel Two</a>
<div>
  <div>Dashboard One</div>
  <div id="dashOne"></div>
</div><div>
  <div>Dashboard Two</div>
  <div id="dashTwo"></div>
</div><hcx-router path="/dash1\/.*/" target="#dashOne" runnable="true" to="#panelOne">
</hcx-router><hcx-router path="/dash2\/.*/" target="#dashTwo" runnable="true" to="#panelTwo"></hcx-router>

Through the use of a less restrictive target CSS selector, it is also possible to target multiple output locations and use multiple routers at the same time!

<a href="#panelOne">Show Panel One</a>  
<a href="#panelTwo">Show Panel Two</a><div>
  <div>Dashboard One</div>
  <div></div>
</div><div>
  <div>Dashboard Two</div>
  <div></div>
</div><hcx-router target=".dashboard"></hcx-router>

Intrigued? Give us a clap and head over to GitHub .


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

世界是平的(3.0版)

世界是平的(3.0版)

[美] 托马斯·弗里德曼 / 何帆、肖莹莹、郝正非 / 湖南科学技术出版社 / 2008-9 / 58.00元

世界变得平坦,是不是迫使我们跑得更快才能拥有一席之地? 在《世界是平的》中,托马斯·弗里德曼描述了当代世界发生的重大变化。科技和通信领域如闪电般迅速的进步,使全世界的人们可以空前地彼此接近——在印度和中国创造爆炸式增长的财富;挑战我们中的一些人,比他们更快占领地盘。3.0版新增两章,更新了报告和注释方面的内容,这些内容均采自作者考察世界各地特别是整个美国中心地带的见闻,在美国本土,世界的平坦......一起来看看 《世界是平的(3.0版)》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具