Reputation: 1980
I am trying to display view by using dynamic routing. For this I am using ":"
notation. Once data comes back from the server, $location.path('/postuser/'+permalink)
is used to redirect to the view. But for some reason I am getting 404 error.
I am using Html 5 mode. I think this the issue.
$location.path('/postuser/'+permalink)
sends request to the server:
instead of this
Here is the router sample
test.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/welcome', {templateUrl: 'partials/welcome.html', controller: 'welcomeController'});
$routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'singupController'});
$routeProvider.when('/signup', {templateUrl: 'partials/signup.html', controller: 'singupController'});
$routeProvider.when('/', {templateUrl: 'partials/home.html', controller: 'homeController'});
$routeProvider.when('/create', {templateUrl: 'partials/new.html', controller: 'CrudController'});
$routeProvider.when('/user/:permalink', {templateUrl: 'partials/userspostpage.html', controller: 'CrudController'});
$routeProvider.otherwise({redirectTo: '/'});
}]);
test.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(true);
}]);
AngularJS files and folder structure
Also in back end I am using ExpressJS router
ExpressJS router
app.get("/postuser/:permalink", daataN);
if I remove /:permalink
from the $routeProvider
I am able to get the response. But I want url to be dynamic
Please let me know what is the issue here
Upvotes: 0
Views: 1085
Reputation: 9351
My guess, since you say you're using html5mode is that the server is handling the route before the client gets a chance, thus you will always trigger the GET action on the server before the angular router has a chance to deal with the request.
I think you have a couple of options:
Upvotes: 1