刷新页面没有提取页眉和页脚?

时间:2017-05-13 18:05:33

标签: angularjs node.js express ngroute

我正在为我的项目使用MEAN堆栈。我必须根据url id显示页面内容

Eg: site.com/product/1

在主页中,我列出了所有产品。如果您点击产品,它将根据ID重定向到此页面。 但我的问题是用户第一次点击产品正确显示页面。但是如果你刷新页面就没有标题。

我使用ng-view显示内容

这是我的代码

了header.html

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
    <link rel="stylesheet" href="includes/style.css" />
<base href="/">
<body>
<ng-view></ng-view>

</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular-route.min.js"></script>
<script src="includes/ng-file-upload-all.js"></script>
<script src="app.js"></script>
<script src="controllers/controllers.js"></script>


</html>

app.js

var myApp = angular.module('myApp',['ngRoute']);
myApp.config(function($routeProvider,$locationProvider){
    $routeProvider
        .when('/product/:id', {
            templateUrl:'templates/product.html',
            controller:'empController'
        })
        .when('/procuctlist', {
            templateUrl:'templates/procuctlist.html',
            controller:'empController'
        });

        $locationProvider.html5Mode(true);
});

server.js

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
var session = require('express-session');
app.all('/', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next()
  });
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(express.static('public'));
app.use(express.static(__dirname + '/client'));
app.use('/', express.static(__dirname + '/client', { redirect: false }));

app.get('/product/:id', function (req, res, next) 
{
    //console.log("client");
    res.sendFile(path.resolve('client/index.html'));
    redirect: true; 
    //next();
});
app.get('/*', function (req, res, next) 
{
    //console.log("client");
    res.sendFile(path.resolve('client/index.html'));
    redirect: true; 
});

app.listen(8000, function(){
    console.log('server is running on port 3000..');
});

请帮我解决这个问题

谢谢

0 个答案:

没有答案