Routing error using angular.js and expression

I am trying to route using angular.js around the / parent root, which works if I use anchor links, etc. (the so-called routing processed exclusively from angular). For example, a link having href '/ parent / createstudent'. However, when I type this in the url line or when I update it when it is already in this place, it generates an error because the backend route has not yet been completed.

Thus, I tried to use the common path ('/ parent / *') in the expression, but this leads to an error when all my js and css are not readable. Does anyone know how to solve this?

My static file directory

public -> javascripts -> app.js -> angular.js -> stylesheets -> images 

Error:

 Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/parent/javascripts/jquery.js". home:1 Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/parent/javascripts/angular.js". home:1 Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/parent/javascripts/main.js". home:1 Uncaught SyntaxError: Unexpected token < jquery.js:1 Uncaught SyntaxError: Unexpected token < angular.js:1 Uncaught SyntaxError: Unexpected token < 

Express

 app.get('/parent', function(req, res) { res.render('main') }); app.get('/parent/*', function(req, res) { res.render('main') }); 

Angular routing (I declare controllers in the view itself)

 var app = angular.module('app', []).config(function($routeProvider, $locationProvider) { $locationProvider.html5Mode(true); $routeProvider.when('/parent/login', { templateUrl: '../templates/login.html' }). when('/parent/home', { templateUrl: '../templates/home.html' }). otherwise( { redirectTo: '/parent' }) }) 
+4
source share
2 answers

You serve your JS / CSS with /parent :

 ... http://localhost:3000/parent/javascripts/jquery.js ^^^^^^^ 

So, if you declare your routes before declaring express.static , your catch-route will handle all JS / CSS requests.

You should use a setting similar to this:

 // express.static() first... app.use('/parent', express.static(__dirname + '/public')); // ...followed by your catch-all route (only one needed) app.get('/parent*', function(req, res) { res.render('main') }); 
+6
source

This is a new โ€œchange of behavior" (or mistake).

Try using the base tag:

 <base href="/" /> 
+16
source

Source: https://habr.com/ru/post/1485170/


All Articles