angular.js - Angular路由和express路由的組合使用問題
問題描述
想用Angular的路由里面監(jiān)聽url變化來獲取不同的ejs模版,但是當(dāng)url一變化express的路由也會(huì)作出反應(yīng),想問下該怎么做才能在url變成/phone時(shí)不進(jìn)入express的路由。
public/javascript/app.js
angular.module(’ngApp’,[]).config([’$routeProvider’,function($routeProvider) { $routeProvider.when(’/’, {templateUrl: ’pages/index’,controller: ’PhoneListCtrl’}).when((’/phone’, {templateUrl: ’pages/phone-detail’,controller: ’PhoneDetCtrl’})).otherwise({redirectTo: ’/’})}])
routes/index.js
var express = reqsuire(’express’);var router = express.Router();router.get(’/pages/phone-detail’, function(req, res, next) { res.render('phone-detail', {title: ’艾希’});})module.exports = router;
下面圖片是結(jié)構(gòu),模版都在view/pages下
問題解答
回答1:兩個(gè)問題1.angularjs和ejs怎么想都感覺重復(fù)了,用angularjs的話就可以使用html+ajax方式,用ejs就可以使用ejs+ajax,說起來不用兩個(gè)都用。2.按說兩個(gè)都用,angularjs的route設(shè)置,加載的頁面是將子頁面異步加載到父頁面的<ng-view>中的,而ejs是整個(gè)瀏覽器窗口的渲染,相當(dāng)于跳頁面了,確實(shí)會(huì)有沖突。
我暫時(shí)能想到的解決方法是,主頁面用ejs跳轉(zhuǎn),子頁面采用ng-route進(jìn)行異步加載,但是缺點(diǎn)就是在ejs和angular的route設(shè)置中不能設(shè)置otherwise。
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. PHP求助,求幫忙謝謝各位3. extra沒有加載出來4. mysql - php 如何網(wǎng)址中出現(xiàn)該頁標(biāo)題?5. javascript - 天貓首頁首屏數(shù)據(jù)來源6. javascript - 釘釘?shù)膃xcel, word文件預(yù)覽是直接用的微軟的office web app,不犯法嗎?7. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列8. django進(jìn)行數(shù)據(jù)庫的查詢9. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時(shí)間會(huì)消失是什么情況?10. mysql - 為什么where條件中or加索引不起作用?
