简体   繁体   English

如何从节点服务器渲染角度路线?

[英]How to render an angular route from node server?

I am newbie in angular+node(express) project. 我是angular + node(express)项目的新手。 I have an angular app with four pages, I have placed that app folder under Public folder of node_modules folder. 我有一个包含四个页面的角度应用程序,已将该应用程序文件夹放置在node_modules文件夹的Public文件夹下。 I am able to access home directory with url "localhost:8081/#/". 我可以使用url“ localhost:8081 /#/”访问主目录。 Now from server.js(node server) I want to load a new page and also want to send some data to display on that page. 现在,从server.js(节点服务器)中,我想加载一个新页面,并且还希望发送一些数据以显示在该页面上。 Following is the code I've written. 以下是我编写的代码。 I have already built pages for website in angular. 我已经建立了网站页面的角度。 so I dont want to use jade or ejs. 所以我不想用玉或ejs。 Tell me the way to do it correctly. 告诉我正确的方法。

app.post('/authenticate',urlencodedParser,function(req,res){
var temp;
res.render( '/#/dashboard', { temp:"tempdata" } );
});

I want to go to a page to which route localhost:8081/#/dashboard is pointing with data temp. 我想转到路由localhost:8081 /#/ dashboard指向数据临时目录的页面。

You are doing it wrongly. 您做错了。 NodeJS should only be used to serve index page and all routing shoud be handled in frontend only. NodeJS仅应用于服务索引页,并且所有路由都应仅在前端处理。 Use angular-route or ui-routes to handle routing. 使用angular-route或ui-routes处理路由。

Serving index page(NodeJS): 服务索引页(NodeJS):

app.route('/').get(res.render('index'));

Creating Routes(Angularjs): 创建路线(Angularjs):

angular.module('core').config(['$stateProvider',
    function($stateProvider) {
        // About state routing
        $stateProvider.
        state('dashboard', {
            url: '/dashboard',
            templateUrl: 'dashboard.html'
        }).state('home', {
            url: '/',
            templateUrl: 'home.html'
        })  
    }
]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM