IronRouter中文指南(精品) .doc
《IronRouter中文指南(精品) .doc》由会员分享,可在线阅读,更多相关《IronRouter中文指南(精品) .doc(38页珍藏版)》请在三一办公上搜索。
1、Guide指南2Quick Start2Concepts概念4Server Only服务端4Client Only客户端4Client and Server 服务端和客户端4Reactivity响应式5Route Parameters路由参数5Rendering Templates 渲染模板7Rendering Templates with Data渲染含数据的模板7Layouts布局8Rendering Templates into Regions with JavaScript含JavaScript的区域渲染模板9Setting Region Data Contexts设置区域数据上下文1
2、0Rendering Templates into Regions using contentFor在contenFor区域渲染模板11Client Navigation客户端导航12Using Links使用链接12Using JavaScript使用JavaScript14Using Redirects使用redirects14Using Links to Server Routes使用服务端Links15Named Routes命名路由15Getting the Current Route获取当前路由16Template Lookup模板查找16Path and Link Templat
3、e Helpers路径和链接模板助手17pathFor17urlFor18linkTo18Route Options路由选项19Route Specific Options特殊的选项19Global Default Options默认全局选项22Subscriptions订阅22Wait and Ready22The subscriptions Option(选项)23The waitOn Option(选项)24Server Routing服务端路由25Creating Routes创建路由25Restful Routes (Rest架构式路由)25404s and Client vs Se
4、rver Routes 404s和客户端 vs 服务端路由26Plugins插件26Applying Plugins to Specific Routes特定的路由应用插件26Creating Plugins创建插件27Hooks钩子27Using Hooks使用钩子27Applying Hooks to Specific Routes特定的路由应用钩子28Using the Iron.Router.hooks Namespace使用Iron.Router.hooks命名空间29Available Hook Methods可用的钩子方法29Server Hooks and Connect服务端
5、钩子和Connect中间件30Route Controllers路由控制器31Creating Route Controllers创建路由控制器32Inheriting from Route Controllers来自路由控制器的继承33Accessing the Current Route Controller访问当前路由控制器34Setting Reactive State Variables设置响应状态变量35Getting Reactive State Variables获取响应状态变量35Custom Router Rendering定制路由器渲染36Legacy Browser S
6、upport传统浏览器支持36补充37Rest架构37路由、路由器、路由控制器的区别37yeild 与 contentFor之间的区别37Guide指南A router that works on the server and the browser, designed specifically for Meteor.iron router是为Meteor设计的一套在服务器和浏览器端工作的路由器。Quick StartYou can install iron:router using Meteors package management system:首先,你需要使用Meteor的扩展包管理系
7、统安装iron:router meteor add iron:routerTo update iron:router to the latest version you can use the meteor update command:若需升级iron:router,则使用Meteor的更新命令 meteor update iron:routerStart by creating a route in your JavaScript file. By default, routes are created for the client and will run in the browser.
8、首先在JavaScript文件中创建一个路由,默认情况是为客户端创建的路由只在浏览器端运行。Router.route(/, function () this.render(Home););When the user navigates to the url /, the route above will render the template named Home onto the page.上述代码是指:当用户导航栏地址为URL根目录,则在该页面执行模板名为“Home”的代码块。Router.route(/items);This second route will automatically
9、 render a template named Items or items to the page. In simple cases like this, you dont even need to provide a route function.上述代码是指:在页面中自动执行模板名Items或items的代码块。在这种情况下,你甚至不需要提供一个路由函数。So far, weve only created routes that will be run directly in the browser. But we can also create server routes. Thes
10、e hook directly into the HTTP request and are used to implement REST endpoints.到目前为止,我们只创建了在浏览器中直接运行的路由。但我们也可以创建服务器端路由。这些钩子直接进入HTTP请求和用于实现REST端点。Router.route(/item, function () var req = this.request; var res = this.response; res.end(hello from the servern);, where: server);The where: server option
11、tells the Router this is a server side route.这个where:server选项告诉路由器,这是服务器端路由。Concepts概念Server Only服务端In a typical Web app, you make an http request to a server at a particular url, like /items/5, and a router on the server decides which function to invoke for that particular route. The function will
12、most likely send some html back to the browser and close the connection.在一个典型的web应用中,一个特殊的url地址会向服务器发送一个http请求,如”/items/5”,服务器上的路由器决定了该特定路由的调用功能。这个功能很可能向浏览器发送一些html并关闭连接。Client Only客户端In some more modern Web apps youll use a client side router like pagejs or Backbone router. These routers run in the
13、 browser, and let you navigate around an application without making trips to the server by taking advantage of browser HTML5 features like pushState or url hash fragments. 在一些流行的web应用中,你会像pagejs 和 Backbone路由一样使用一个“客户端”路由。这些路由器运行在浏览器中,并让你在不访问服务器的情况下,通过获取高级的浏览器hmtl5功能,导航周边应用,如pushState(无刷新更新)、url 哈希片段
14、。Client and Server 服务端和客户端Iron.Router runs on the client and the server. You can define a route that only should run on the server, or a route that should only run on the client. Most of the time youll create routes on the client. This makes your app really fast once its loaded, because as you navig
15、ate around the application, you dont need to load an entirely new html page.Iron.Router运行于客户端和服务端。你可以定义一个路由,只在服务端运行或只在客户端运行。大多数情况会在客户端创建路由。使得你的应用一旦加载很快响应,因为在你浏览周边应用时,不需要加载一个全新的HTML页面。The router is aware of all the routes on the client and the server. This means you can click a link that takes you to
16、 a server route, or it might take you to a client route. It also means that on the server, if there is no client route defined, we can send a 404 response to the client instead of loading up the Meteor application.路由器知道所有在客户端和服务端的路由。这意味着你可以点击一个链接,便会带你到一个服务端路由,也有可能带你到客户端路由。这也意味着在服务器上,如果没有定义客户端路由,我们可以
17、向客户端发送404响应,而不是加载的Meteor应用。Reactivity响应式Your route functions and most hooks are run in a reactive computation. This means they will rerun automatically if a reactive data source changes. For example, if you call Meteor.user() inside of your route function, your route function will rerun each time th
18、e value of Meteor.user() changes.你的route函数和大多数钩子是在响应计算周期内运行的。这意味着如果反应数据源发生改变,它们将自动重新运行。例如,如果在路由函数内调用Meteor.user(),你的路由函数将返回每次Meteor.user()的值变化。Route Parameters路由参数Routes can have variable parameters. For example, you can create one route to show any post with an id. The id is variable depending on t
19、he post you want to see such as /posts/1 or /posts/2. To declare a named parameter in your route use the : syntax in the url followed by the parameter name. When a user goes to that url, the actual value of the parameter will be stored as a property on this.params in your route function.路由可以有可变参数。例如
20、,创建一个路由,用于显示任意带有id的post。这个id变量依赖于你想看到关于post是什么值;如/posts/1 或 /posts/2。在你的路由中声明一个被命名的参数:是在URL的语法后跟着参数名。当用户调转到该URL时,该参数的实际值将被存储在你的路由函数this.params属性中。In this example we have a route parameter named _id. If we navigate to the /post/5 url in our browser, inside of the route function we can get the actual
21、value of the _id from this.params._id. In this case this.params._id = 5.在下面的例子中,我们定义一个命名为_id的路由参数。如果在浏览器中导航到”/post/5”地址,在路由函数内部,我们可以通过”this.params._id”获取”_id”的实际值。在这种情况下this.params._id=5。/ 获取一个像 /post/5的地址Router.route(/post/:_id, function () var params = this.params; / _id: 5 var id = params._id; /
22、5);You can have multiple route parameters. In this example, we have an _id parameter and a commentId parameter. If you navigate to the url /post/5/comments/100 then inside your route function this.params._id = 5 and mentId = 100.可以添加多个路由参数。在下面的例子中,我们有”_id” 和”commentId”两个参数。假设你的跳转(导航)地址是/post/5/comme
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- IronRouter中文指南精品 IronRouter 中文 指南 精品

链接地址:https://www.31ppt.com/p-2388824.html