0

I have a project Using Spring and Angular JS. When I attempt to remove the ungly "/#/", I followed the following tutorial:

Configuring HTML 5 mode

in my index html file:

<base href="/">

in my AngularJS config:

app.config(
    function ($stateProvider, $urlRouterProvider, $locationProvider) {
        $urlRouterProvider.otherwise("/");

        .state('business', {
            abstract: true,
            url: "/",
            templateUrl: "business/businessView"
        })

        .state('business.intro1', {
            url: "/intro1",
            templateUrl: "business/page-1",
        })

        $locationProvider.html5Mode({enabled: true)};
    }
);

So In order to support resource, I added following JAVA code to my spring controller

@RequestMapping(value = "/{[path:[^\\.]*}")
public String redirect() {
    return "forward:/";
}

@RequestMapping("/business/**")
public String returnBusinessHtml() {
    String uri = request.getRequestURI().substring(request.getContextPath().length());
    return  uri;
}

and successfully avoided 404 issue when directly access URL.


Everything is looking good for now, however, when I add a URL to the abstract controller of angularJS:

.state('business', {
    abstract: true,
    url: "/business",
    templateUrl: "business/businessView"
})

the 404 issue came out again when I tried to access localhost:8080/business/intro1.

If I try other page like localhost:8080/businessLanding, It's OK.

Maybe the issue came out from @RequestMapping(value = "/{[path:[^\\.]*}") this regular expression? Please help, thanks!

1 Answer 1

0

Forgive me, I just modified it to the original solution:

@RequestMapping(value = "/**/{[path:[^\\.]*}")
public String redirect() {
    return "forward:/";
}

and everything is done!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.