grails - 在Grails 3.2.3中的 Controller 重定向中,在网址的开头添加#/。

标签 grails

我正在Grails中构建一个自定义的 Angular 应用程序,但是要尽可能地遵循默认的Grails Controller View行为。

我想做的是:使用脚手架 Controller 。获得相同的行为,但是在网址的开头加上#/。这样,在保存记录后,您将被重定向到:

http://localhost:8080/#/country/show/5

代替

http://localhost:8080/country/show/5

这样Angular会再次出现。我知道这不是标准的Angular行为,但由于我对 Angular 了解很少,因此我尝试使用尽可能少的 Angular 文件。

默认的脚手架重定向为:

重定向国家

我尝试使用:

重定向基础:“#/”,国家

重定向国家/地区,[基础:“#/”]

重定向国家/地区,基础:“#/”

重定向绝对:“#/”,国家

但是它们在被调用时都会抛出500错误。

这是我当前在 Angular 应用程序配置:

app.config(function($routeProvider) {
    $routeProvider.when("/:controller/:action",{
        templateUrl:function(params){
            return '/'+params.controller+'/'+params.action;
        }
    })
    .when("/:controller/:action/:param",{
        templateUrl:function(params){
            return '/'+params.controller+'/'+params.action+'/'+params.param;
        }
    });
});

最佳答案

你有试过吗

class SomeController {
    LinkGenerator linkGenerator

    def action() {
        redirect uri: linkGenerator.link(
            controller: 'country', action: 'show', id: 5, base: '/#')
    }
} 

更新:鉴于需要支持多种格式,因此教导使用“漂亮” URL的 Angular 可能是唯一的方法。 Here is an example posting具有以下代码:
angular.module('scotchy', [])
    .config(function($routeProvider, $locationProvider) {

        $routeProvider
            .when('/', {
                templateUrl : 'partials/home.html',
                controller : mainController
            })
            .when('/about', {
                templateUrl : 'partials/about.html',
                controller : mainController
            })
            .when('/contact', {
                templateUrl : 'partials/contact.html',
                controller : mainController
            });

        // use the HTML5 History API
        $locationProvider.html5Mode(true);
    });

关于grails - 在Grails 3.2.3中的 Controller 重定向中,在网址的开头添加#/。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41169392/

相关文章:

unit-testing - 使用 Intellij IDE 的 Grails 单元和集成测试文件名冲突

Grails:有没有办法让 findAll() 没有查询但有分页和排序?

oracle - grails tomcat 7部署

spring - 在同一台机器(不同的Jetty服务器)中的两个Grails应用程序的Spring缓存

java - 独立的 Java 应用程序可以使用 Grails 模型吗?

grails - 使用Kendo UI上传文件

tomcat - 如何在 grails 中指定可移植的 jndi 数据源查找

rest - REST API和普通API之间有什么区别?

grails - 获取实例列表,Grails

grails - 如何使用 angular 2 的 grails 配置文件