Browse Source

L5: Active Links

Frederic G. MARAND 9 năm trước cách đây
mục cha
commit
c1accbc356
4 tập tin đã thay đổi với 27 bổ sung7 xóa
  1. 11 5
      index.html
  2. 3 2
      modules/App.js
  3. 10 0
      modules/NavLink.js
  4. 3 0
      styles.css

+ 11 - 5
index.html

@@ -1,7 +1,13 @@
-<!doctype html public="storage">
+<!DOCTYPE html>
 <html>
-<meta charset=utf-8/>
-<title>My First React Router App</title>
-<div id=app></div>
-<script src="bundle.js"></script>
+  <head>
+    <meta charset=utf-8/>
+    <title>My First React Router App</title>
+    <link rel="stylesheet" href="styles.css" />
+  </head>
 
+  <body>
+    <div id=app></div>
+    <script src="bundle.js"></script>
+  </body>
+</html>

+ 3 - 2
modules/App.js

@@ -1,4 +1,5 @@
 import { Link } from "react-router";
+import NavLink from './NavLink';
 import React from "react";
 
 export default React.createClass({
@@ -8,8 +9,8 @@ export default React.createClass({
         <h1>React router tutorial</h1>
         <ul role="nav">
           <li><Link to="/">Home</Link></li>
-          <li><Link to="/about">About</Link></li>
-          <li><Link to="/repos">Repos</Link></li>
+          <li><NavLink to="/about">About</NavLink></li>
+          <li><NavLink to="/repos">Repos</NavLink></li>
         </ul>
         { this.props.children }
       </div>

+ 10 - 0
modules/NavLink.js

@@ -0,0 +1,10 @@
+import React from 'react';
+import { Link } from 'react-router';
+
+export default React.createClass({
+  render() {
+    return (
+      <Link {...this.props} activeClassName="active" />
+    )
+  }
+})

+ 3 - 0
styles.css

@@ -0,0 +1,3 @@
+a.active {
+  color: red;
+}