In an Angular setting, I have chose Angular UI-router to switch between views.
My config looks as follows:
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/app/home');
$stateProvider
// Nav
.state('app', {
url: '/app',
templateUrl: 'templates/navbar.html',
abstract: true,
controller:'AppCtrl as app',
})
// Home
.state('app.home', {
url: '/home',
templateUrl: 'templates/home.html',
controller:'HomeCtrl as home',
})
.state('app.browse', {
url: '/browse',
templateUrl: 'templates/browse.html',
controller:'BrowseCtrl as browse',
})
.state('app.browse-detail', {
url: '/browse/:productId',
templateUrl: 'templates/browse-detail.html',
controller:'BrowseDetailCtrl as detail',
})
})
This will result that the url of a product will appear as follows:
www.website.com/app/#/browse/productId
Instead I would like to see something like:
www.website.com/browse/productId/most-awesome-product
where most-awesome-product
is an Url Slug.
My questions are:
Thanks!
A simple workaround to this problem is to use a dynamic rendering tool that helps create static HTML files for web crawlers to index easily. You can then set up your web server to send the search engine crawlers to the pre-rendered pages, and the visitors will be redirected to your regular Angular website.
Are Web Slugs Important for Search Engine Ranking? The short answer is yes. Using SEO keywords in your URL can help you rank for your target keywords. Google uses the URL as a factor in ranking your page, so if the URL slug includes your keywords, then Google will be more likely to rank it.
A custom AngularJS filter for converting a string into a url slug. A slug is a url & seo friendly string containing only lowercase alphanumeric characters and hyphens "-". Slugs are often used for including titles in URLs for SEO. (function () { 'use strict'; angular . module('app') .
You need to use the html5Mode for that
In web.config add
$locationProvider.html5Mode(true);
In index.html page
<base href="/">
It is enough but when you will refresh the page it will give the error so need to use url re-writing, so add in web.config
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
And your state will need to change, like this
.state('app.browse-detail', {
url: '/browse/:productId/:slug',
templateUrl: 'templates/browse-detail.html',
controller:'BrowseDetailCtrl as detail',
For more detail see AngularJS HTML5 mode reloading page not found solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With