Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何转到定义了角度配置的url的父url_Javascript_Html_Node.js_Angularjs_Angular Routing - Fatal编程技术网

Javascript 如何转到定义了角度配置的url的父url

Javascript 如何转到定义了角度配置的url的父url,javascript,html,node.js,angularjs,angular-routing,Javascript,Html,Node.js,Angularjs,Angular Routing,让我谈谈我的应用程序:我正在尝试使用node和angular构建一个网页。在/(根)url上,我提供了用于注册和登录的表单。我在这里没用角形的。成功登录后,我正在/home上加载angular脚本和配置文件。以下是我的angular配置文件: window.app.config(['$routeProvider', '$locationProvider', function($routeProvider,$locationProvider) { $locationProv

让我谈谈我的应用程序:我正在尝试使用node和angular构建一个网页。在/(根)url上,我提供了用于注册和登录的表单。我在这里没用角形的。成功登录后,我正在/home上加载angular脚本和配置文件。以下是我的angular配置文件:

window.app.config(['$routeProvider', '$locationProvider',
    function($routeProvider,$locationProvider) {
        $locationProvider.html5Mode(true);
        $locationProvider.hashPrefix('!');
        $routeProvider.
        when('/profile', {
            templateUrl: '/views/account.html',

        }).
        when('/edit', {
            templateUrl: '/views/edit.html',

        }).
        when('/home', {
            templateUrl: 'views/index.html'
        }).
        when('/signout', {
            templateUrl: 'views/signout.html'
            //on this view i load a controller which submits a form to /signout
        }).

        otherwise({
            redirectTo: '/home'
        });
    }
]);
在服务器端路由上:

app.get('/',function(){
      res.render('index',{
         user: req.user? req.user:'guest'
    });
});
app.post('/login',function(){
         //if success redirect to /home
         //if fails redirect to /
});
app.get('/signout',function(){
         //signing out the user here...and redirects to /
});
app.get('/home',function(req,res){
    res.render('users/home',{
      user: req.user? req.user:'guest',
      message: req.flash('error')

    })
  }); 
app.get('/profile',function(req,res){
    res.render('users/home',{
      user: req.user? req.user: 'guest',
      message: req.flash('error')

    })
  });
  app.get('/edit',function(req,res){
    res.render('users/home',{
      user: req.user? req.user:'guest',
      message: req.flash('error')

    })
  });

现在问题来了。假设我在/home-url中。如果我单击此链接,此页面将包含链接登录页。此链接会将我重定向到/home而不是/。如何解决此问题?帮助提示:(

根据配置中的定义,您告诉angular重定向到
/home

...
        when('/signout', {
            templateUrl: 'views/signout.html'
        }).

        otherwise({
            redirectTo: '/home'
        });
如果希望默认值为
/
,请将其更改为:

...
        when('/signout', {
            templateUrl: 'views/signout.html'
        }).

        otherwise({
            redirectTo: '/'
        });

在应用程序配置中,没有路径被指定为“/”,否则也会指定“/home”,因此您被重定向到/home,请尝试在配置中配置“/”路径抱歉。忘记在此处添加签出详细信息。请签出。我现在添加了。我尝试重定向“/”。如果我这样做,我显然会重定向到/但问题是此请求不会成功服务器。它只是在我加载ng视图的地方显示空白。标题保持不变。因此,如果登录失败,您将重定向到服务器上的
/
。为什么不重定向回服务器上的
/login
?我的登录或注册表单位于
/
上。用户只能在
/login
上发布。如果成功
/home
加载并使用angular配置启动。否则,将他重定向到
/
,并显示错误消息hmmm,如何进入
/
页面开始?在浏览器上写入
localhost