HTML5路由器:router5
router5是一個HTML5 路由器,簡單并且強大。基于 route-node 和 path-parser。
特性
- Use of hash (#)
- Default start route: a default route to navigate to on load if the current URL doesn't match any route. Similar to$routeProvider.otherwise()in Angular ngRoute module.
- Start and stop router
- Nested named routes: routes are identified by names and parameters so you don't have to manipulate URLs directly. Routes can be nested, introducing the notion of route segments.
- Route change listeners: listen to any route change, or register listeners for a specific route.
- Route node change listeners: you can add listeners to be triggered on a specific named route node. They will be triggered if that named route node is the node a component tree needs to be re-rendered from.
- Segments deactivation: you can register segment components. On a route change, it will ask those components through theircanDeactivatemethod if they allow navigation. Similar to Angular 2 and Aurelia routers.
- You are in control! You decide what to do on a route change and how to do it. </ul>

// Route definitions
var router = new Router5()
.setOption('useHash', true)
// Users
.addNode('users', '/users')
.addNode('users.view', '/view/:id')
.addNode('users.list', '/list')
// Orders
.addNode('orders', '/orders')
.addNode('orders.completed', '/completed')
.addNode('orders.pending', '/pending')
.addNode('orders.view', '/details/:id')
// Listener
.addListener(drawGraph)
// Start
.start();
function drawGraph(toState, fromState) { / ... / }
// Init
drawGraph(router.getState());</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!