My AngularJS project uses html5mode, I do these codes to open html5mode
In HTML:
...
<base href="/features-A/">
...
In JS:
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5mode(true)
}])
NOTE: the /features-A/ is not an actual folder in my project, it is just a behavior defined in AWS CloudFront, Because we also have some URL /features-B point to other projects, We only need to know that: Whether it is accessed via "http://myhost.com" or "http://myhost.com/features-A/" is the entry file for my project: index.html
Here is what the browser does:
when going to my "Sign In" page, The URL in the address bar is
http://myhost.com/features-A/signin
When going to "Home" page, The URL in the address bar is
http://myhost.com/features-A/ome
As we see, AngularJS changed the URL via History API add /features-A/ inside to the URL
What I want
when people access "Sign In", The URL does not have /features-A/:
http://myhost.com/signin
When people access the "Home" page, The URL has /example:
http://myhost.com/features-A/home
This will make our website looks like the Sign In page is a system that is independent and outside /features-A/.
What I tried
I have tried some solutions however they haven't worked:
Set base href Dynamically In stateChangeSuccess event but URL still changed
Use HTML5 history API pushState and replaceState function, this way would cause page refresh indefinitely
So, Is there any solution to solve this problem?
how do not you create a new virtual host?
via php
php -S localhost:8080
type this Command in your folder's project
Related
the user when reading the qrcode, he should be redirected to an internal page that is hidden, he could only be redirected through this link
I tried using some libs like https://pub.dev/packages/qr_code_scanner but it doesn't do what I wan
It worked, I passed a Get.toName('pageName');
I want to reload the page with different html page using angularjs $window, the documation says:
Page reload navigation
The $location service allows you to change only the URL; it does not allow you to reload the page. When you need to change the URL and reload the page or navigate to a different page, please use a lower level API, $window.location.href.
So I set the loaction to the page $window.location.href = '/transaction';
and the matching route on config block:
app.config(function($routeProvider) {
$routeProvider
.when('/transaction', {
templateUrl : 'JavaScript/directives/modelHTML/Transaction.html',
controller : 'endProcessModelController'
});
});
But instrad of Transaction.html page I get Error 404: SRVE0190E: File not found: /transaction with the route mydomain.com/UI/transaction.
BTW - templateUrl url's works fine in other place like UImodel so the problam is the navigation I think.
Set the location to the page $window.location.href = '#/transaction'; .
'#' indicating location the startpage which is normally index.html. so the link will be index.html#/transaction.Since its a single page app
i think in your config do
'/UI/transaction' instead of `/transaction`
and in the link do $window.location.href = '#/UI/transaction'
Is the mydomain.com/UI/transaction address correct (you use html5 mode)?
Does the problem occur when you try to enter directly into mydomain.com/UI/transaction?
If so, the problem is wrong server configuration (eg .htaccess file).
Try this
$location.path($window.location.origin +'/transaction');
And if you feel all the routes have something extra after the origin you can set a <base href="..."> for that and tell angular from where to take the rest amount of text for route purpose.
If you redirect the page with your_origin/transaction your browser will make a request to the server of /transaction, which the server will be not able to understand and 404 will come. But the route is client side (browser) routeing, so If you are routing to route /abc your javascript code is interpreting that, and invokes the corrosponding operations, (might be a different call to server for the html template or some data dependency, and then instantiating the controller and attach to view). So the moment you are trying to route your javascript code should be loaded.
Either you go for a ui-router where the route comes after # and this allow the browser to play after the text of (#) and not to reloading.
Or, make your server such a way, If a unidentified request comes you should return the base (index) page, so it will load all the scripts and that js will do the rest. (But obviously you will loose all the existing data in that state)
Is it possible to serve a dynamic html page without a backend server or without using a front-end framework like Angular?
Edit
To clarify, the index file is served from a backend. This question is about how to handling routing between the index and dynamic pages.
I have an application that consists of two files - index.html and dynamic.html. When the user clicks an option say "Option A", they are served dynamic.html and the url is updated to /option-a. Now, with a server this is no problem and assuming the user visits the app from the landing page, it isn't a problem either because a cookie can be set. However, suppose a user visits a page at my-domain/option-a. That route doesn't exist and there is no server to redirect so it will 404. They would have to visit dynamic.html.
I think this architecture demands that there's either a server to handle route redirects or a SPA framework.
Is there something I'm missing?
your SPA framework will be active only once your HTML page is loaded and to do that you need to redirect any URL that user tries for your domain to that HTML file. For this you obviously need a server (and since you are talking about my-domain/option-a I assume you have atleast a basic server). You can refer to this link to get an idea on how server can redirect a URL to specific html file: Nodejs - Redirect url.
Once HTML is loaded you can initialize your SPA framework and decide the template to be loaded based on the URL.
Note: without a server you will access URLs using file://somepath/index.html and anything other than this URL will result in 404 and no SPA framework can handle that.
I think the solution is to use a static site generator such as Jekyll or Middleman and allows you to convert information into static pages. That way you functionally are building a bunch of pages but they are all compiled ahead of time. You can add dynamic content that is loaded in from a yaml file and it will compile the content into separate html pages.
It is not possible, but there is a workaround using url parameters like this:
my-folder/index.html
my-folder/index.html?=about
my-folder/index.html?=about/sublevel
my-folder/index.html?=profile
my-folder/index.html?=./games
const urlParams = new URLSearchParams(location.search);
const route = urlParams.get('');
console.log(route);
// Should print "about" "about/sublevel" "profile" "./games"
Of course this approach is not as clean as using a server for routing, but it's the best you can get without a server.
BTW. I tried an alternative solution creating symlinks with all the target routes pointing to the same index.htmlfile. But it did not work because the browser (firefox) redirects by default when it finds a symlink, thus home is shown all the time.
Actual Requirement
click on share button
generate a text/url/link
share this with other users via whatsapp/fb/twitter/email etc.
onclick of this link, my app opens with data passed in the link.
similar to youtube link like: https://youtu.be/g5MIJ3Us10k
What Is done till now...
I have a deeplink URL in String form.
It works perfectly when I access it as the hyperlink on a browser and my app opens correctly.
I need to create this URL string as hyperlink that can be shared among other apps from the app itself.
Using following code to generate share link
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "MyAPPLink");
shareIntent.putExtra(Intent.EXTRA_TEXT, url); //String deeplink url
return shareIntent;
I able to share text to other apps, but it's not a link rather plain text.
How can I make it a hyperlink, so that when user share it to the other app, other users can click on the link and open the app and pass the data in the link?
UPDATE
Following is the deeplink url format
url = intent://#Intent;scheme=;package=;S.browser_fallback_url=;end;
UPDATE 2
I have created a link to my website and appended my deeplink data
like http://example.com/deeplink?id=1234567
I have uploaded a HTML file without UI and using JS I am able fetch my ID in the script.
Now when script runs, my app is not launching but divert to fallback url.
If I put a button in HTML and onclick of that button I run the script, my application launches.
How can I launch my app from generated shared text???
I think I have resolved it. It is now working on my device with the chrome browser as default. Need to test with other combinations.
The issue was with JS. I put my redirect call inside setTimeout() and it worked.
Here is the logical flow
Create an intent filter with scheme, view action and browsable+default category in manifest
Create a share intent and setExtra text as http://example.com/deeplink?id=12345
Create an empty HTML file and using JS, fetch the query and extract "id"
Now using setTimeout(), call redirect deep link URL --> intent://#Intent;scheme=;package=;S.browser_fallback_url=;end;
In the Activity exposed to deeplink, get dataString from intent and extract ID passed by deeplink
I hope this helps others :)
Instead of using hash URLs for my SinglePageApplication I would like to use the HTML5 Browser History API. This works fine so far (I'm using emberjs).
The pro of the hash URL is, I can refresh the page without worrying about the result. When I try to reload with the browser history API I'll get a 404 (since my server don't have a route for this).
So: Is there a common workaround to avoid this behaviour?
I could tell my server to redirect to the index page but this wouldn't show me the correct content.
Example:
GET host/#images
... shows the "images" page (even when it is the index.html)
GET host/images
... redirect to host/
... shows me the content of the index template
Is https://stackoverflow.com/a/17288940/1423583 an answer to your question? Basically it says that you have to change the server to always serve the index.html page.