Angular JS application page refresh issue - javascript

I am working on an angular application and i have used "$locationProvider.html5Mode(true)" in my route config to avoid /#/ in URL. I have also added base href="/" in index.html and everything is working fine on refresh of pages.
But when i am trying to refresh the page having URL
"http://localhost:3000/home/:JavaScipt%20SC2.0"
Then i am getting Cannot GET /home/:JavaScipt%20SC2.0 error.
I think error is due to name "JavaScript SC2.0" containing .(dot) symbol. Any clue to fix this issue?

But when i am trying to refresh the page having URL
"http://localhost:3000/home/:JavaScipt%20SC2.0"
Your route has at least two problems:
First, document name misspelled, shouldn´t it be JavaScript? (with R)
Second, you can´t use home/ : Jav... (/:Javascipt??)
try again with http://localhost:3000/home/JavaScript SC2.0 into a variable and pass it.
More info in this link
PS: If (whoever) knows so much that can mark my answer as not valid, please ALSO post a valid answer, not just a negative ;)

you can try on send it on another state:
or you can use the $window dependency into your controller, and use as javascript.

Related

Strapi custom auth controller

I'm using Strapi for my API and Back office. Everything works fine except one thing: I can't figure out how to override the controller that is used for the forgot password feature. I've tried to follow the documentation, especially this page : https://strapi.io/documentation/3.0.0-beta.x/admin-panel/customization.html#development-mode but no chance.
Here what I've tried :
Create a folder admin at the root of the project, inside which I created controller/Auth.js. In this file I created my custom forgotPassword function but it's not called.
Add the file admin/config/routes.json, my controller got the same name but I thought that maybe I need to repeat the route here to override, still not successful.
I saw on some page that to get what I was searching I needed to put those files (config/routes.json and controller/Auth.js) inside /extensions/user-permissions/admin, but it's still not working.
Whatever I try, it's always the default forgot password controller that is called, from the strapi-admin node modules.
Any help would be greatly appreciated, I don't see what I'm missing here.
It's normal, because your are not writing the file in the right place.
So I will help you with that.
First here is the documentation for the customization - https://strapi.io/documentation/3.0.0-beta.x/concepts/customization.html#plugin-extensions
Then we have to find the file in the code source we want to update.
Here is the function - https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L266
Based on the file path and the way to customize in strapi.
You will have to create a file to this path extensions/users-permissions/controllers/Auth.js
Then create a module.exports with source code function and the update it.
this should work

Angular interpolating {{ }} in url params, is there a way to sanitize the url?

We have an edge case issue where an external application requires a specific url parameter to be present in the url request to our website:
https://stackoverflow.com/questions/ask?abc=123
Here is a screenshot:
Occasionally, the url parameter will not render correctly causing the url to become:
https://stackoverflow.com/questions/ask?abc={{}}
We have angular running on our application, it cannot parse this causing unnecessary errors for the webpage.
Does angular have a way of encoding the url before it hits the app?
Details
Angular 1.6.6
Current Solution
We have a temporary nginx redirect solution in place but believe its better if we fixed the source of the issue.
We've done a lot of reading into changing the template tags but this is a huge fix.
Expected
We don't use any custom url variables. We want to it not throw an error and function normally as expected when not parse https://stackoverflow.com/questions/ask?abc={{}}
You need to bind the parameter in [queryParams]="{ 'abc':'test' }"
Since a object needs to be passed, you can create the object dynamically in typescript.
Try like this:
HTML:
<a [routerLink]="['https://stackoverflow.com/questions/ask']" [queryParams]="getQueryParam()">Link</a>
TS:
getQueryParam() {
var queryParam = {};
queryParam['abc'] = this.some_variable;
return queryParam;
}
The issue may be related to this:
https://github.com/angular/angular.js/commit/5930b8ee27e441aa4422d9174dcc7eb7db30e400.
Which is saying it is a known issue with Angular.
Upon research, we have found that Drupal render forms using a function called request_uri(), which does not encode the output. Consequently, the action url causes angular to error when it loads on the page.
The solution to this we found is adding in a redirect.

Changing pages URLs without using route controllers

First of all, sorry for the lame question (probably). I tried to search for an answer but I'm not finding everything I need for my issue.
So... I have a bootstrap website and I am trying to change the page URLS to appear like this :
For example : www.site.com/AboutUs.html - to appear as www.site.com/about-us
I am using the pushState method for this as it follows:
var stateObj = { AboutUs: "about-us" };
history.pushState(stateObj, "About Us", "about-us");
So I get the needed URL address there (www.site.com/about-us).. so far so good. But on page refresh it throws an error stating "The requested URL /about-us was not found on this server."
If I hit the back browser button it goes to www.site.com/AboutUs.html again.(and it is supposed to go on the home page)
My question is :
What am I missing, am I supposed to make a controller and how ?
I am not using C#, I can probably use some help with PHP because I am not good at it. JavaScript / jQuery are welcomed.
Thanks in advance and sorry for the dumb question.
Happy days!
The point of pushState is to be able to say: I have modified the page with JavaScript, the new state is what you would get if you just asked the server for this URL.
You shouldn't use JavaScript for this problem at all. You just want to have a page appear at a particular URL.
You need to configure the server to serve up the content you want on the URL you want.
What am I missing, am I supposed to make a controller and how ?
You need something on the server to handle the URL /about-us.
"A controller" is something you would probably use if you were using the MVC architecture on the server … and it doesn't sound like you are.
More likely you will be wanting to use an Alias, a tool like mod_write, or simply moving the static file to a directory called about-us and renaming it index.html.

Angular adding a hashtag at the end of file path url in $location

So, some quick context: I'm building an electron app, so all paths/urls are from file system. Web window starts with a small form, with user/password, and then it redirects to the main app that uses angular. The form is using GET, by the way.
After the redirect, the plan was to get the query parameters with $location, but angular is adding a hashtag and slash at the end of it, and when I try to $location.search() it gives me an empty object.
$location.absUrl() is returning: file:///C:/blablabla/main.html?user=abc&password=123#/
So my guess is that hashtag at the end is ruining all my plans. And it's weird, because I'm not using any $route/$location/$state configuration. By the way, the window.location object has the correct path without the hashtag, so I'm guessing this is angular's fault.
I did some search and found some recommendations to use html5Mode, but after trying it seems to not work the way I need, since it needs a baseurl tag with a path.
Any help is going to be appreciated, thanks

Get the url parameter or the part of the url after the question mark (?) of an included php file

I basically have this "info.php" file included in another php file which is "main_page.php". By clicking a link in the page, the link sends a url parameter to the "info.php" file through javascript by reloading the page, giving it a new url. The "info.php" file then, for instance, becomes "info.php?student=1" which is, again, to be clear, included inside the "main_page.php" file. I've researched for solutions but what I only found are those javascripts and php scripts that gets the current url in the address bar.
Is there a way to do this, getting the new url of an included php file? If there is, then please forgive me for my dumbness and irresponsibly inadequate researching. Thank you so much.
This is what you are looking for.
$_SERVER['QUERY_STRING']
Here is the documentation
You should be able to access your URL query variables through the global $_GET array.
$_GET['student']
If not, please edit your question with some actual code like to have a better idea of what you are trying to achieve.

Categories

Resources