Saturday 13 May 2017

Refreshing page not fetching header and footer?

I am using MEAN stack for my project.Here I have to display a page content based on url id

Eg: site.com/product/1

In home page I am listing all the products.If you click a product it will redirect to this page based on id. but my problem is first time a user click the product its showing the page correctly. but if you refresh the page it's not taking the header.

I am using ng-view for displaying the content

Here is my code

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..');
});

Please help me to solve this issue

Thank you



via Athi

No comments:

Post a Comment