我创建了一个具有多个从屏幕右侧滑入的面板的网站。
我希望能够在每个共享我的网页的面板上放置一个链接,当用户访问该网站时,该特定面板将打开。
例如:
www.something.com/#/panel-1
将显示我的页面,其中 panel-1 打开,同时:
www.something.com/#/panel-2 将显示我的页面,其中 panel-2 打开。
最简单的方法是什么?我可以仅通过简单的 html 使用 Ember、Angular 或 Backbone 的路由器和 View 吗?我应该只使用 router.js 之类的东西吗?
如有任何帮助、建议或链接,我们将不胜感激。
最佳答案
当然可以。这是 ember.js 最强的品质之一。声明路由后,框架可以自动生成所有相应的 Controller 和 View (这称为约定优于配置)。查看示例
Ember.Application.create({});
Ember.Router.map(function(){
this.route('panel1');
this.route('panel2');
});
<script type="text/x-handlebars">
{{link-to 'index' 'index'}}
{{link-to 'first panel' 'panel1'}}
{{link-to 'second panel' 'panel2'}}
<!--your panels will be inserted automatically in the outlet property-->
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="panel1">
panel 1
</script>
<script type="text/x-handlebars" data-template-name="panel2">
panel 2
</script>
关于javascript - 实现路由以显示某些 View 的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26940327/