【问题标题】:routing of static website using nodeJs使用nodeJs路由静态网站
【发布时间】:2016-09-01 11:37:41
【问题描述】:

我使用 Angular js 构建了一个网站。但这不是SPA。我使用 Angular js 进行 API 调用并仅获取一些数据,所以现在我想为我的 HTML 页面的自定义 URL 进行路由,我该怎么做?我正在使用 nodeJs 为我的网站提供服务。 node js中是否有任何配置来设置静态网站/路由的自定义URL。

【问题讨论】:

  • 你能详细解释一下这个要求吗,如果我能更好地理解你想要达到的目标,我可能会提供帮助。

标签: angularjs node.js routing


【解决方案1】:

要在 nodejs 中使用路由,您可以使用 express.Router() 模块。它可以像 express 一样安装,然后您可以在其上定义路由。 例如:-

     var adminRouter = express.Router();
     adminRouter.get('/',function(req,res){
         res.send('Here is the dashboard for my app');
     });
     adminRouter.get('/users',function(req,res){
         res.send('Here is the menu to show all the users');
     });

     //Now to apply the routes to your app

     app.use('/admin',adminRouter);

你也可以单独路由你应用的中间件和url参数

【讨论】:

    猜你喜欢
    • 2021-05-23
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    相关资源
    最近更新 更多