vdecaster
vdecaster

Reputation: 201

ui-router url parameter with hashtag

I'm working on the routing of my angular application, but I can't seem to find the following:

example.com/#parameter

In this url the #parameter should stay #parameter and get the param data. Now it removes the # and goes to example.com/parameter

If I go to example.com/#parameter it should do the same as it would if I go to example.com/parameter

I have the following in my app.js

 url: "/:bandName"

and send this data to my controller with $stateParams

Is there any way to keep the hashtag in the url ?

-- edit

so here is some code that works on enter with /#parameter

        $urlRouterProvider.when(':#bandName', '/:bandName')
                .otherwise('/');
        $stateProvider.state('appband', {
                    url: "/:bandName",
                    templateUrl: "main.php",
                    controller: 'mainController'
        })

 $locationProvider.html5Mode(true);

With this if I go to example.com/#randomBandName I get redirected to example.com/randomBandNameand I get randomBandName as parameter in my controller

So what I need is on enter that example.com/#randomBandName stays example.com/#randomBandName and that I still get randomBandName in my controller.

But when I remove $urlRouterProvider.when(':#bandName', '/:bandName') I just get an empty page.

Upvotes: 5

Views: 1445

Answers (1)

jusopi
jusopi

Reputation: 6813

There are a few things that look suspect with this:

trailing slash

Are you using HTML5 mode for your URLs? I'd suggest using this URL setup url: "/parameter" if you indeed see param as more of a resource.

You might also read this - https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-make-a-trailing-slash-optional-for-all-routes

query param

If you are intending param to be a query parameter then you need this..

url: "/?parameter"

more on that here - https://github.com/angular-ui/ui-router/wiki/URL-Routing#query-parameters

Upvotes: 1

Related Questions