2

我正在page.js使用Single Page Application. 出于测试目的,我正在使用npm http-server.

我无法进行路由。我不确定我错过了什么。以下是我的代码:

索引.html:

<html>
<head>
  <title>test page!</title>
  <script src="/js/libs/page.js"></script>
</head>
<body>
  this is body of test
  <a href="/test">Simple test</a>

  <script type="text/javascript" src="/js/routes.js"></script>
</body>
</html>

路由.js

function initRoutes () {
  var testRoutes = {
    test : function (context, next) {
      alert("testing");

      if(next){
        next();
      }
    },
    test2 : function (context, next) {
      alert("I am jon snow, I know nothing.");
    }
  };
  page.base('/');

  page('/', testRoutes.test);
  page('/test', testRoutes.test2);
  page('/two-args', testRoutes.test, testRoutes.test2);
  page();
}
initRoutes();

从我的http-server,我正在访问http://0.0.0.0:8081。我得到一个测试alert,但我没有得到alert路由http://0.0.0.0:8081/test

我不确定我错过了什么。如果您需要其他任何东西,请告诉我。

4

0 回答 0