2017-01-31 8 views
7

का उपयोग करते समय ExpressJS रूटिंग को हल करने का तरीका मैं बैक 4app BaaS सेवा का उपयोग कर रहा हूं जो पार्स-सर्वर का उपयोग करता है। क्लाइंटसाइड के लिए मैं html5Mode (सत्य) के साथ AngularJS चला रहा हूं; http://app.rizop.tv/dashboard हालांकि यह सही काम कर रहा है: http://app.rizop.tvAngularJS html5Mode (back4app/parse-server)

किसी भी विचार कैसे सही तरीके से मेरी मार्गों को संभालने के लिए expressJS ठीक करने के लिए

मेरे समस्या यह है कि इस काम नहीं कर रहा है?

बादल \ app.js

// Helper modules that will be used 
var path = require('path'); 
var bodyParser = require('body-parser') 

// This imports the Router that uses the template engine 
var index = require('./routers/index'); 

// Sets the template engine as EJS 
app.set('view engine', 'ejs'); 

// This defines that the 'views' folder contains the templates 
app.set('views', path.join(__dirname, '/views')); 

// These options are necessary to 
app.use(bodyParser.urlencoded({ extended: false })) 
app.use(bodyParser.json()) 

// This bind the Router to the/route 
app.use('/', index) 

// Starts listening in the routes 
app.listen(); 

बादल \ रूटर \

// Importing express 
var express = require('express'); 

// Creating a Router 
var route = express.Router(); 

// Defining a route that binds the GET method 
route.get('/', function(req, res) { 
    // This is the code that renders the template 
    res.render('index', {testParam: 'Back4Apper'}); 
}); 

module.exports = route; 

बादल \ विचारों index.js \ index.ejs:

मैं इस config है

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    ... 
</body> 
... 
</body> 
</html> 

यहाँ मेरी एप्लिकेशन संरचना होती है:

enter image description here

उत्तर

2

आप इसे app.js और जड़ html फ़ाइल

में थोड़ा परिवर्तन करके काम कर सकते हैं मुझे लगता है आप पहले से ही $locationProvider.html5Mode(true); परिभाषित जहाँ आप अपने मार्गों परिभाषित । फिर अपने सूचकांक html में आधार href परिभाषित

<head> 
    <base href="/"> 
    ... 
</head> 

This answer अपने सर्वर

+0

नहीं, वही त्रुटि: http://app.rizop.tv/dashboard। पहले से ही है। – lito

1

बादल पर फ़ाइल कॉन्फ़िगर करने के लिए उपयोगी हो सकता है/app.js अपने अंतिम लाइन पर app.listen नहीं किया जाना चाहिए था() के कारण तथ्य यह है कि आप क्लाउड कोड का उपयोग कर रहे हैं। क्या आप कोशिश कर सकते हैं?

+0

नहीं, वही त्रुटि: http://app.rizop.tv/dashboard – lito

0

मैं एक ही समस्या में पड़ गए और निम्न

मैं अंतिम विकल्प के रूप में इस मार्ग रख दिया है, इसलिए जब एक्सप्रेस रूटर विकल्पों में से बाहर भाग यह इंडेक्स फ़ाइल जहां कोणीय अनुप्रयोग है प्रदान करेगा किया है । कोणीय आंतरिक राउटर उस मार्ग को हल करेगा और दृश्य खींचेंगे।

router.get('*', function (req, res) { 
    res.render('index', {testParam: 'Back4Apper'}); 
}); 

जाहिर है आप एक होशियार regex बजाय * की अपनी आवश्यकताओं के अनुसार लिख सकते हैं, लेकिन आप विचार मिलता है।