我声明的状态没有被接收?

时间:2017-01-21 07:56:40

标签: angularjs angular-ui-router

我有这个代码,每次输入“localhost:3000 / page1”都没有任何反应,我得到的不能得到/ page1,这是代码..

var module = angular.module('ngFirstApp',['ui.router']);

module.config(function($stateProvider, $urlRouterProvider,$locationProvider) {

    $stateProvider
        .state("home",{ url: "/", template: "This is home"  })
        .state("page1",{ url: "/page1", template: "this is page"});

    // Prety the URL
    $locationProvider.html5Mode({enabled:true,requireBase: false}); 
    $urlRouterProvider.otherwise("/"); // always declare this for any URL that might be typed

});

请我失去理智..当我把一个胡言乱语的网址放到“/”状态时怎么样?怎么了!??我很沮丧这个..小时和小时寻找答案..

更新: 继承我的server.js代码,如果它可能有帮助,如果你想知道我是否添加了UI路由器,我在我的html中做了并且在开发工具网络选项卡中双重检查没有错误。叹息如此沮丧。

var express = require('express');
var app     = express();
var path    = require('path');  // native js node path

// set routing to ejs and change its default view folder
app.set('view engine','ejs');
app.set('views',path.resolve(__dirname,'client','views'));

// serve static files
app.use(express.static(__dirname + '/client'));

// set our main ejs view index file
app.get('/',function(req, res){
    res.render('views/index');// use the render to use ejs templating
})

// make app listen to port 3000 or any port
app.listen(3000, function(){
    console.log('Server is running... at port: '+ 3000);
})

1 个答案:

答案 0 :(得分:1)

我可以看到您的应用程序部署在local server中,然后根据您使用的服务器类型,您必须先指定web application name才能将其导航到'movies'应用程序的页面。

假设您部署的应用程序为localhost:3000/movies,则localhost:3000/yourdirectory/page1将带您进入电影目录的默认索引,即初始化Web应用程序的位置。

因此,在您的情况下,请尝试UrlRequest这可能对您有所帮助!