Skip to content

Commit 6fb9af9

Browse files
committed
Resolved #27: Don't use absolute path for actions in MVC template.
1 parent 35c2df9 commit 6fb9af9

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

src/AbpCompanyName.AbpProjectName.WebMpa/AbpCompanyName.AbpProjectName.WebMpa.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
<Compile Include="Models\Layout\TopMenuViewModel.cs" />
346346
<Compile Include="Properties\AssemblyInfo.cs" />
347347
<Compile Include="Views\AbpProjectNameWebViewPageBase.cs" />
348+
<Compile Include="Views\UrlChecker.cs" />
348349
</ItemGroup>
349350
<ItemGroup>
350351
<Content Include="Views\web.config" />

src/AbpCompanyName.AbpProjectName.WebMpa/App_Start/AbpProjectNameNavigationProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public override void SetNavigation(INavigationProviderContext context)
1818
new MenuItemDefinition(
1919
"Home",
2020
new LocalizableString("HomePage", AbpProjectNameConsts.LocalizationSourceName),
21-
url: "/",
21+
url: "",
2222
icon: "fa fa-home"
2323
)
2424
).AddItem(
2525
new MenuItemDefinition(
2626
"About",
2727
new LocalizableString("About", AbpProjectNameConsts.LocalizationSourceName),
28-
url: "/About",
28+
url: "About",
2929
icon: "fa fa-info"
3030
)
3131
);

src/AbpCompanyName.AbpProjectName.WebMpa/Views/Layout/_TopMenu.cshtml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
@using Abp.Collections.Extensions
2+
@using AbpCompanyName.AbpProjectName.WebMpa.Views
23
@model AbpCompanyName.AbpProjectName.WebMpa.Models.Layout.TopMenuViewModel
4+
@{
5+
var calculateMenuUrl = new Func<string, string>((url) =>
6+
{
7+
if (string.IsNullOrEmpty(url))
8+
{
9+
return ApplicationPath;
10+
}
11+
12+
if (UrlChecker.IsRooted(url))
13+
{
14+
return url;
15+
}
16+
17+
return ApplicationPath + url;
18+
});
19+
}
320
@foreach (var menuItem in Model.MainMenu.Items)
421
{
522
<li class="@(Model.ActiveMenuItemName == menuItem.Name ? "active" : "")">
623
@if (menuItem.Items.IsNullOrEmpty())
724
{
8-
<a href="@menuItem.Url">
25+
<a href="@calculateMenuUrl(menuItem.Url)">
926
@if (!string.IsNullOrWhiteSpace(menuItem.Icon))
1027
{
1128
<i class="@menuItem.Icon"></i>
@@ -26,7 +43,7 @@
2643
@foreach (var subMenuItem in menuItem.Items)
2744
{
2845
<li>
29-
<a href="@subMenuItem.Url">
46+
<a href="@calculateMenuUrl(subMenuItem.Url)">
3047
@if (!string.IsNullOrWhiteSpace(subMenuItem.Icon))
3148
{
3249
<i class="@subMenuItem.Icon"></i>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace AbpCompanyName.AbpProjectName.WebMpa.Views
4+
{
5+
public static class UrlChecker
6+
{
7+
private static readonly Regex UrlWithProtocolRegex = new Regex("^.{1,10}://.*$");
8+
9+
public static bool IsRooted(string url)
10+
{
11+
if (url.StartsWith("/"))
12+
{
13+
return true;
14+
}
15+
16+
if (UrlWithProtocolRegex.IsMatch(url))
17+
{
18+
return true;
19+
}
20+
21+
return false;
22+
}
23+
}
24+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function() {
22
abp.event.on('abp.notifications.received', function (userNotification) {
3-
console.log(userNotification);
3+
abp.notifications.showUiNotifyForUserNotification(userNotification);
44
});
55
})();

src/AbpCompanyName.AbpProjectName.WebSpaAngular/App/Main/views/layout/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
});
1616

1717
abp.event.on('abp.notifications.received', function (userNotification) {
18-
console.log(userNotification);
18+
abp.notifications.showUiNotifyForUserNotification(userNotification);
1919
});
2020
}
2121
]);

0 commit comments

Comments
 (0)